Test Instructions Link
Test instructions: Give a graph that tells you the color of the edges between each point (with a heavy edge) and asks you how many sides are connected between any two points.
Solution: and set Processing, F[x][c]: Represents the x link and the color is C's vertex y
AAA: Posture is not timed out, the correct posture is unordered_map, and the violent traversal of the time to cycle small
#include <bits/stdc++.h> using namespace std; #define LL Long Long #define PB push_back #define X first #define Y second #define CL (b) memset (A,b,sizeof (a)) typedef p
Air<int,int> P;
const int maxn=100005;
Const LL inf=1<<27;
Const LL MOD=1E9+7;
Unordered_map<int,int> F[MAXN],ANS[MAXN]; int getf (int x,int c) {return x==f[x][c]?x:f[x][c]=getf (f[x][c],c);} void Union (int c,int x,int y) {if (f[x].count
(c) ==0) f[x][c]=x;
if (F[y].count (c) ==0) f[y][c]=y;
X=GETF (F[X][C],C);
Y=GETF (F[Y][C],C);
if (x==y) return;
if (x>y) swap (x, y);
F[x][c]=y;
} int main () {int n,m,q;
scanf ("%d%d", &n,&m);
for (int i=0;i<m;i++) {int u,v,c;
scanf ("%d%d%d", &u,&v,&c);
if (u>v) swap (U,V);
Union (C,U,V);
} scanf ("%d", &q);
while (q--) {int x,y;scanf ("%d%d", &x,&y);
if (F[x].size () >f[y].size ()) swap (x, y);///optimization is important int ans=0; if (Ans[x].count (y)) {printf ("%d\n", Ans[x][y]); continue;}
for (auto K:f[x]) {if (F[y].count (k.x) ==0) continue;
if (GETF (f[x][k.x],k.x) ==getf (f[y][k.x],k.x)) ans++;
} Ans[x][y]=ans;
printf ("%d\n", Ans);
} return 0;
}