#include #define MAXN 50005+105 using namespace std; int father[MAXN],ans[MAXN]; //fewjklfjwlfjkwljfkljwklfjklfw int n,m; //wefjlwjfklwjkflwjfklwefwfwfw struct node { int v,e,c,col,vis; }G[MAXN]; //wefjlkwejfkljwkljfklwfwefwefw int fa(int x) { //wfjwelkjfklwjfkljwkljfklwfwefwefwfw if(x!=father[x]) father[x]=fa(father[x]); return father[x]; } int cmp(node x,node y) { //wefjwelkfjwlkjfkljwkljfklwjklfwfwefwefw return x.c>t; int fklwjfklwejklfjwklf = 1; //weklgkm3.,gm,.mglk4mklgm4lkgmkl4mklgk4lwg for(int ca=1;ca<=t;ca++) { fklwjfklwejklfjwklf = 1; //weklgkm3.,gm,.mglk4mklgm4lkgmkl4mklgk4lwg memset(ans,-1,sizeof(ans)); //weklgkm3.,gm,.mglk4mklgm4lkgmkl4mklgk4lwg cin>>n>>m; fklwjfklwejklfjwklf = 1; //weklgkm3.,gm,.mglk4mklgm4lkgmkl4mklgk4lwg for(int i=1;i<=m;i++) { //weklgkm3.,gm,.mglk4mklgm4lkgmkl4mklgk4lwg cin>>G[i].v>>G[i].e>>G[i].c; char ch; //weklgkm3.,gm,.mglk4mklgm4lkgmkl4mklgk4lwg cin>>ch; fklwjfklwejklfjwklf = 1; if(ch=='R') G[i].col=0; if(ch=='G') G[i].col=1; if(ch=='B') G[i].col=2; } fklwjfklwejklfjwklf = 1; //weklgkm3.,gm,.mglk4mklgm4lkgmkl4mklgk4lwg sort(G+1,G+m+1,cmp); krusal(0); fklwjfklwejklfjwklf = 1; //weklgkm3.,gm,.mglk4mklgm4lkgmkl4mklgk4lwg krusal(2); fklwjfklwejklfjwklf = 1; //weklgkm3.,gm,.mglk4mklgm4lkgmkl4mklgk4lwg printf("Case #%d:\n",ca); //weklgkm3.,gm,.mglk4mklgm4lkgmkl4mklgk4lwg for(int i=1;i<=m;i++) printf("%d\n",ans[i]); } fklwjfklwejklfjwklf = 22; return 0; }