ODD personalitytime limit:2000msmemory limit:32768kbthis problem would be judged onLightoj. Original id:1300
64-bit integer IO format: %lld Java class name: Main
Being an odd person, Jim always liked odd numbers. One day he is visiting his home town which consists of n places and m bidirectional roads. A Road always connects, different places and there are at the most one road between, places. The places is numbered from 0 to n-1.
Jim wants to find a tour which starts from a place p and each time it goes to a new road and finally at Last step it returns back to p. As Jim likes odd numbers, he wants the length of the tour to be odd. And the length of a tour are defined by the number of roads used in the tour.
For the city map given above, 0-1-2-0 are such a tour, so, 0 are one of the results, since from 0, a tour of odd length is found, similarly, 1-2-0-1 are also a valid tour. But 3-2-0-1-2-3 are not. Since the road 2-3 is used twice. Now given the city map, Jim wants to find the number of places where he can start his journey for such a tour. As you is the best programmer in town, he asks you to help. Jim can use a place more than once, but a road can is visited at most once in the tour.
Input
Input starts with an integer T (≤30), denoting the number of test cases.
Each case starts with a blank line. The next line contains the integers: n (3≤n≤10000) and m (0≤m≤20000). Each of the next m lines contains-integers u v (0≤u, v < n, u≠v) meaning that there is a bidi Rectional Road between Place u and v. The input follows the above constraints. And no road is reported more than once.
Output
For each case, print the case number and the total number places where Jim can start his journey.
Sample Input
1
6 6
0 1
1 2
2 0
3 2
3 4
3 5
Sample Output
Case 1:3
Source
Problem Setter:jane Alam to solve the problem: the approximate meaning is to see how many starting point, starting from this point, the last after the odd number of edges back to the starting point, but not through the same side, you can have the same point. It's obvious that you're looking for a strange circle on the side.
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =50000;4 structArc {5 intTo,next;6Arcintx =0,inty =-1) {7to =x;8Next =y;9 }Ten} e[maxn<<2]; One intHEAD[MAXN],DFN[MAXN],LOW[MAXN],COLOR[MAXN]; A intTot,idx,cnt,n,m,flag,ans; - BOOLB[MAXN]; - voidAddintUintv) { theE[tot] =arc (V,head[u]); -Head[u] = tot++; - } - voidTarjan (intUintFA) { +Dfn[u] = Low[u] = + +idx; - for(inti = Head[u]; ~i; i =E[i].next) { + if(!Dfn[e[i].to]) { A Tarjan (e[i].to,u); atLow[u] =min (low[u],low[e[i].to]); - if(Low[e[i].to] > Dfn[u]) b[i] = b[i^1] =true; -}Else if(e[i].to = FA) Low[u] =min (low[u],dfn[e[i].to]); - } - } - voidDfsintUints) { inColor[u] =s; -cnt++; to for(inti = Head[u]; ~i; i =E[i].next) { + if(B[i])Continue; - if(Color[e[i].to] && color[e[i].to] = = Color[u]) flag =1; the Else if(Color[e[i].to] = =0) DFS (E[i].to,3-s); * } $ }Panax Notoginseng intMain () { - intT,cs =1, u,v; thescanf"%d",&T); + while(t--) { Ascanf"%d%d",&n,&m); thememset (head,-1,sizeof(head)); +memset (Low,0,sizeof(Low)); -memset (DFN,0,sizeof(DFN)); $memset (Color,0,sizeof(color)); $memset (b,false,sizeof(b)); -IDX =0; - for(inti = tot =0; I < m; ++i) { thescanf"%d%d",&u,&v); - Add (u,v);Wuyi Add (v,u); the } - for(inti = ans =0; I < n; ++i) Wu if(!dfn[i]) Tarjan (i,-1); - for(inti =0; I < n; ++i) About if(Color[i] = =0) { $Flag = CNT =0; -DFS (I,1); - if(flag) ans + =CNT; - } Aprintf"Case %d:%d\n", cs++, ans); + } the return 0; -}
View Code
Lightoj 1300 ODD Personality