http://poj.org/problem?id=2513
Initially see the first feeling---map a look at 250000 of the amount of data decisively give up
Then remember to read it before, Trie instead of map, especially when the amount of data is particularly large
Learned:
1, Trie instead of the idea of map, you can at the end of the word TREE[I][TK] this I as a string corresponding to the int value, of course, this int value can also be used to establish and check the set
2, connected, through and check set judgment, all the points in the same set map is Unicom, otherwise not unicom, note that tree[i][tk]>0 is the end of the word,
X=find (x);//This sentence does not have the time to debug a few ... int flag=1; for (int i=1;i<top;i++) { if (TREE[I][TK] && x!=find (i)) { flag=0; break; } if (tree[i][tk]%2) cnt++; }
Note that the father does not guarantee that all the points in the same set are identical, so it is still important to determine whether the same collection is in the same set through Find (x) ==find (y), and cannot father equal judgment.
3, non-Tuola access to the existence of the decision:
A, unicom, and check the set to do
b, the number of degrees is odd is 0 or 2---------------0 of the non-direction of the existence of the Euler loop, 2 non-map exists Oraton road is half Eulerian graph
#include <cstdio> #include <cstring> #include <string> #include <map> #include <iostream> #include <cmath>using namespace std; #define INF 10000const int tk=26,tb= ' a '; const int N = 5000000+1000;//2500000+10 00;//int d[n];int tree[n][tk+1],top,n;int Father[n],pos[n],scnt;char pat1[15],pat2[15];void init () {top=1; scnt=n=0; memset (tree[0],0,sizeof (tree[0)); MakeSet for (int i=0;i<n;i++) father[i]=i;} int Insert (char *s, int rank=0) {int rt,nxt; for (rt=0; *s; rt=nxt,++s) {NXT=TREE[RT][*S-TB]; if (!NXT) {nxt=tree[rt][*s-tb]=top; memset (tree[top],0,sizeof (tree[top)); top++; }} tree[rt][tk]++; return RT;} int Find (int x) {if (x!=father[x]) Father[x]=find (father[x]); return father[x];} void Union (int x, int y) {x=find (x), Y=find (y); if (x==y) return; Father[y]=x;} int main () {//freopen ("Poj2513.txt", "R", stdin); Init (); int cnt=0,x,y; while (SCANF ("%s%s", PAT1,PAT2)!=eof) {X=insert (PAT1); Y=insert (PAT2); Union (x, y); } x=find (x);//This sentence does not have the time to debug a few times ... int flag=1; for (int i=1;i<top;i++) {if (TREE[I][TK] && x!=find (i)) {flag=0; Break } if (tree[i][tk]%2) cnt++; } if (! ( cnt==2 | | CNT = = 0)) flag=0; if (flag) printf ("possible\n"); else printf ("impossible\n"); return 0;}