Let's go home

Source: Internet
Author: User

Hdu1824: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1824

Question: Chinese.

Question: two constraints must be considered when this question is created. One is internal to the team, that is, if a, B, c, a --> ~ B, B --> ~ A; A --> ~ C, C --> ~ A; at the same time, B and C must be left at the same time, so B --> C, C --> B ;~ B --> ~ C ,~ C --> ~ B; that is, B needs to stay C, C needs to stay B, B does not stay C, C does not stay B does not need to stay;, and then the situation of each pair, you can directly create an edge.

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 using namespace STD; 6 int T, M, N; 7 const int n = 200010; 8 const int M = 400010; 9 const int INF = 0 xffffffff; 10 struct edge {11 int to, next; 12} edge [m]; 13 int CNT, U, V, DEP, top, Atype; 14 int dfn [N], low [N], vis [N], head [N], st [N], belong [N], in [N], out [N], sum [N]; 15 // sum [I] records the number of vertices in the I-connected graph. In [I], out [I] indicates the inbound and initial degrees of the vertex after the contraction. 16 void Init () {17 CNT = Dep = Top = Atype = 0; 18 memset (Head,-1, sizeof (head); 19 memset (dfn, 0, sizeof (dfn); 20 memset (low, 0, sizeof (low); 21 memset (VIS, 0, sizeof (VIS); 22 memset (belong, 0, sizeof (belong); 23 memset (in, 0, sizeof (in); 24 memset (Out, 0, sizeof (out); 25 memset (sum, 0, sizeof (SUM); 26} 27 void addedge (int u, int v) {28 edge [CNT]. to = V; 29 edge [CNT]. next = head [u]; 30 head [u] = CNT ++; 31} 32 33 void Tarjan (int u) {3 4 dfn [u] = low [u] = ++ Dep; 35 st [top ++] = u; 36 vis [u] = 1; 37 For (INT I = head [u]; I! =-1; I = edge [I]. Next) {38 int v = edge [I]. To; 39 if (! Dfn [v]) {40 Tarjan (V); 41 low [u] = min (low [u], low [v]); 42} 43 else if (vis [v]) {44 Low [u] = min (low [u], dfn [v]); 45} 46} 47 Int J; 48 if (dfn [u] = low [u]) {49 Atype ++; 50 do {51 J = sT [-- top]; 52 belong [J] = Atype; 53 sum [Atype] ++; // records the number of the midpoint of each connected component 54 vis [J] = 0; 55} 56 while (u! = J); 57} 58} 59 int FG [N], T1, T2, T3; 60 int main () {61 while (~ Scanf ("% d", & T, & M) {62 int A, B, C; 63 int base = 3 * t; 64 Init (); 65 for (INT I = 0; I <t; I ++) {66 scanf ("% d", & A, & B, & C ); 67 addedge (B, c); 68 addedge (C, B); 69 addedge (B + base, C + base); 70 addedge (C + base, B + base ); 71 addedge (a + base, B); 72 addedge (a + base, c); 73 addedge (B + base, a); 74 addedge (C + base, ); 75} 76 while (M --) {77 scanf ("% d", & A, & B); 78 addedge (A, B + base ); 79 addedge (B, A + base); 80} 81 For (INT I = 0; I <6 * t; I ++) 82 If (! Dfn [I]) 83 Tarjan (I); 84 bool flag = false; 85 for (INT I = 1; I <3 * t; I ++) {86 If (belong [I] = belong [I + base]) {87 flag = true; 88 break; 89} 90} 91 If (! Flag) printf ("Yes \ n"); 92 else93 printf ("NO \ n"); 94} 95 96}
View code

 

Let's go home

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.