Title Link: Http://codeforces.com/contest/501/problem/C
Test instructions: Gives the sum of the degrees of each vertex of the graph and the XOR values of the adjacent vertices, and the number of edges and edges of the graph:
Analysis: Find the point of a degree, the corresponding XOR value is the adjacent vertex (<-^), and then the number of adjacent vertices minus one:
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <queue >using namespace Std;const int maxn=1<<16+5;int du[maxn],ytot[maxn];vector< pair<int, int > > V;int Main () {int n,u,v; int i; while (scanf ("%d", &n)!=eof) {queue<int> Q; for (i=0;i<n;i++) v.clear (); for (i=0;i<n;i++) scanf ("%d%d", &du[i],&ytot[i]); for (i=0;i<n;i++) if (du[i]==1) Q.push (i); while (! Q.empty ()) {U=q.front (); Q.pop (); if (du[u]!=1) continue; V=ytot[u]; V.push_back (Make_pair (u,v)); du[v]--; Ytot[v]^=u; if (du[v]==1) Q.push (v); } printf ("%d\n", V.size ()); For (I=0;i<v.size (); i++) printf ("%d%d\n", v[i].first,v[i].second); } return 0;}
Codeforces #285 Div.2 C. Misha and Forest