Bzoj1603/p2913 [usaco 08oct] Wheel Rotation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.