Title Link: Http://codeforces.com/problemset/problem/501/C
Test instructions
Ideas:
Code:
#include <iostream>#include<stdio.h>#include<cstring>#include<queue>#include<Set>#include<cmath>#include<time.h>#include<cstdlib>#include<algorithm>#defineLson (i<<1)#defineRson (lson|1)using namespaceStd;typedefLong LongLL;Const intN =1000007;Const intINF =0x7fffffff;structnode{intidx; intde; intVal;} Dt[n];structans{intA, B;} Ans[n];intN, Vis[n], Cnt_ans;voidBFs () {Queue<int>que; for(inti =0; I < n; i++) { if(Dt[i].de = =1) {Vis[i]=1; Que.push (i); } } while(!Que.empty ()) { intt =Que.front (); Que.pop (); structNode temp =Dt[t]; if(Dt[temp.idx].de = =0) Continue; ANS[CNT_ANS].A=Temp.idx; ANS[CNT_ANS].B=Temp.val; Cnt_ans++; Dt[temp.val].de--; Dt[temp.val].val^=Temp.idx; if(Dt[temp.val].de = =1&&!Vis[temp.val]) {Vis[temp.val]=1; Que.push (Temp.val); } }}intMain () {Ios_base::sync_with_stdio (0); Cin.tie (0); while(Cin >>N) {Cnt_ans=0; memset (Vis,0,sizeof(VIS)); for(inti =0; I < n; i++) {Dt[i].idx=i; CIN>> dt[i].de >>Dt[i].val; if(Dt[i].de = =0) Vis[i]=1; } BFS (); cout<< Cnt_ans <<Endl; for(inti =0; i < Cnt_ans; i++) cout<< ans[i].a <<" "<< ans[i].b <<Endl; } return 0;}
Codeforces 501C Misha and Forest (BFS)