P2913 [usaco 08oct] Wheel Rotation
To be secure (to prevent data leakage), BFs is used.
Each transfer can be solved directly with an exclusive or.
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <queue> 5 # define re register 6 using namespace STD; 7 void read (Int & X) {8 char c = getchar (); X = 0; 9 While (! Isdigit (c) c = getchar (); 10 while (isdigit (c) x = (x <3) + (x <1) + (C ^ 48), c = getchar (); 11} 12 # define n 100213 queue <int> H; 14 int N, d [N]; bool vis [N]; 15 int CNT, HD [N], NXT [n <1], Ed [N], poi [n <1], val [n <1]; 16 void Adde (int x, int y, int v) {17 NXT [Ed [x] = ++ CNT; HD [x] = HD [x]? HD [x]: CNT; 18 ed [x] = CNT; poi [CNT] = y; Val [CNT] = V; 19} 20 int main () {21 read (n); int Q1, q2, Q3; 22 for (Re int I = 1; I <n; ++ I) {23 read (Q1 ); read (Q2); read (Q3); Q3 ^ = 1; // returns the inverse of the result to make it easier for the following XOR or 24 Adde (Q1, q2, Q3); Adde (Q2, q1, Q3); 25} 26 h. push (1); D [1] = 1; vis [1] = 1; 27 while (! H. empty () {28 int x = H. front (); H. pop (); 29 for (INT I = HD [X]; I; I = NXT [I]) {30 int to = poi [I]; 31 if (! Vis [to]) {32 d [to] = d [x] ^ Val [I]; 33 If (to = N) {34 printf ("% d ", d [N]); 35 return 0; 36} 37 vis [to] = 1; 38 H. push (to); 39} 40} 41} 42}View code
Bzoj1603/p2913 [usaco 08oct] Wheel Rotation