Language: C++

#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > nei[1000005];
vector<int> cit[1000005];
vector<int>comp;
int col[1000005];
bool vis[1000005];
vector<int>newnei[1000005];
int dp[1000005];
 int poi[1000005];
 queue<int> q;                //无需跑最短路，直接写bfs，用queue 
 int main()
 {
     int n,m;
     cin>>n>>m;
     memset(col,-1,sizeof col);
     for(int i=0;i<m;i++)
     {
         int x,y,c;
         scanf("%d %d %d",&x,&y,&c);
         x--,y--,c--;
         nei[x].push_back(make_pair(c,y));
         nei[y].push_back(make_pair(c,x));
         cit[c].push_back(x);
         cit[c].push_back(y);
         comp.push_back(c);
     }
     sort(comp.begin(),comp.end());
     comp.erase(unique(comp.begin(),comp.end()),comp.end());
     for(int i=0;i<n;i++)
     {
         sort(nei[i].begin(),nei[i].end());
     }
     int newci=n;
     for(int i=0;i<comp.size();i++)
     {
         int cmp=comp[i];
         for(int j=0;j<cit[comp[i]].size();j++)
         {
             int v=cit[comp[i]][j];
             if(col[v]==cmp) continue;
             q.push(v);
             col[v]=cmp;
             vector<int> ciin;
             while(!q.empty())
             {
                 v=q.front();
                 ciin.push_back(v);
                 q.pop();
                 int k=0;
                 for(;poi[v]<nei[v].size();poi[v]++)            //这里的poi[v]很好的利用了按公司编号从小到大的单调性 
                 {
                     k=poi[v];
                     if(nei[v][k].first!=cmp) break;
                     int u=nei[v][k].second;
                     if(col[u]==cmp) continue;
                     col[u]=cmp;
                     q.push(u);
                 }
             }
             for(int k=0;k<ciin.size();k++)
             {
                 int v=ciin[k];
                 newnei[v].push_back(newci);
                 newnei[newci].push_back(v);
             }
             newci++;
         }
     }
     for(int i=0;i<newci;i++) dp[i]=-2;
     dp[0]=1;
     q.push(0);
     while(!q.empty())
     {
         int v=q.front();
         q.pop();
         for(int k=0;k<newnei[v].size();k++)
         {
             int u=newnei[v][k];
             if(dp[u]==-2)
             {
                 dp[u]=dp[v]+1;q.push(u);
             }
             
         }
     }
     cout<<dp[n-1]/2;
 }#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > nei[1000005];
vector<int> cit[1000005];
vector<int>comp;
int col[1000005];
bool vis[1000005];
vector<int>newnei[1000005];
int dp[1000005];
 int poi[1000005];
 queue<int> q;                //无需跑最短路，直接写bfs，用queue 
 int main()
 {
     int n,m;
     cin>>n>>m;
     memset(col,-1,sizeof col);
     for(int i=0;i<m;i++)
     {
         int x,y,c;
         scanf("%d %d %d",&x,&y,&c);
         x--,y--,c--;
         nei[x].push_back(make_pair(c,y));
         nei[y].push_back(make_pair(c,x));
         cit[c].push_back(x);
         cit[c].push_back(y);
         comp.push_back(c);
     }
     sort(comp.begin(),comp.end());
     comp.erase(unique(comp.begin(),comp.end()),comp.end());
     for(int i=0;i<n;i++)
     {
         sort(nei[i].begin(),nei[i].end());
     }
     int newci=n;
     for(int i=0;i<comp.size();i++)
     {
         int cmp=comp[i];
         for(int j=0;j<cit[comp[i]].size();j++)
         {
             int v=cit[comp[i]][j];
             if(col[v]==cmp) continue;
             q.push(v);
             col[v]=cmp;
             vector<int> ciin;
             while(!q.empty())
             {
                 v=q.front();
                 ciin.push_back(v);
                 q.pop();
                 int k=0;
                 for(;poi[v]<nei[v].size();poi[v]++)            //这里的poi[v]很好的利用了按公司编号从小到大的单调性 
                 {
                     k=poi[v];
                     if(nei[v][k].first!=cmp) break;
                     int u=nei[v][k].second;
                     if(col[u]==cmp) continue;
                     col[u]=cmp;
                     q.push(u);
                 }
             }
             for(int k=0;k<ciin.size();k++)
             {
                 int v=ciin[k];
                 newnei[v].push_back(newci);
                 newnei[newci].push_back(v);
             }
             newci++;
         }
     }
     for(int i=0;i<newci;i++) dp[i]=-2;
     dp[0]=1;
     q.push(0);
     while(!q.empty())
     {
         int v=q.front();
         q.pop();
         for(int k=0;k<newnei[v].size();k++)
         {
             int u=newnei[v][k];
             if(dp[u]==-2)
             {
                 dp[u]=dp[v]+1;q.push(u);
             }
             
         }
     }
     cout<<dp[n-1]/2;
 }

Compiler output:
a.cc:88:3: error: stray '#' in program
   88 |  }#include<bits/stdc++.h>
      |   ^
a.cc:88:4: error: 'include' does not name a type
   88 |  }#include<bits/stdc++.h>
      |    ^~~~~~~
a.cc:90:24: error: redefinition of 'std::vector<std::pair<int, int> > nei [1000005]'
   90 | vector<pair<int,int> > nei[1000005];
      |                        ^~~
a.cc:3:24: note: 'std::vector<std::pair<int, int> > nei [1000005]' previously declared here
    3 | vector<pair<int,int> > nei[1000005];
      |                        ^~~
a.cc:91:13: error: redefinition of 'std::vector<int> cit [1000005]'
   91 | vector<int> cit[1000005];
      |             ^~~
a.cc:4:13: note: 'std::vector<int> cit [1000005]' previously declared here
    4 | vector<int> cit[1000005];
      |             ^~~
a.cc:92:12: error: redefinition of 'std::vector<int> comp'
   92 | vector<int>comp;
      |            ^~~~
a.cc:5:12: note: 'std::vector<int> comp' previously declared here
    5 | vector<int>comp;
      |            ^~~~
a.cc:93:5: error: redefinition of 'int col [1000005]'
   93 | int col[1000005];
      |     ^~~
a.cc:6:5: note: 'int col [1000005]' previously declared here
    6 | int col[1000005];
      |     ^~~
a.cc:94:6: error: redefinition of 'bool vis [1000005]'
   94 | bool vis[1000005];
      |      ^~~
a.cc:7:6: note: 'bool vis [1000005]' previously declared here
    7 | bool vis[1000005];
      |      ^~~
a.cc:95:12: error: redefinition of 'std::vector<int> newnei [1000005]'
   95 | vector<int>newnei[1000005];
      |            ^~~~~~
a.cc:8:12: note: 'std::vector<int> newnei [1000005]' previously declared here
    8 | vector<int>newnei[1000005];
      |            ^~~~~~
a.cc:96:5: error: redefinition of 'int dp [1000005]'
   96 | int dp[1000005];
      |     ^~
a.cc:9:5: note: 'int dp [1000005]' previously declared here
    9 | int dp[1000005];
      |     ^~
a.cc:97:6: error: redefinition of 'int poi [1000005]'
   97 |  int poi[1000005];
      |      ^~~
a.cc:10:6: note: 'int poi [1000005]' previously declared here
   10 |  int poi[1000005];
      |      ^~~
a.cc:98:13: error: redefinition of 'std::queue<int> q'
   98 |  queue<int> q;                //无需跑最短路，直接写bfs，用queue
      |             ^
a.cc:11:13: note: 'std::queue<int> q' previously declared here
   11 |  queue<int> q;                //无需跑最短路，直接写bfs，用queue
      |             ^
a.cc:99:6: error: redefinition of 'int main()'
   99 |  int main()
      |      ^~~~
a.cc:12:6: note: 'int main()' previously defined here
   12 |  int main()
      |      ^~~~