Colored sticks POJ-2513 (trie tree Oralu)

Source: Internet
Author: User

Test instructions

Is the Tuola road without direction.

Analytical:

Cannot use map. Timeout

In judging whether there is only one unicom, I prefer to use set, but also can not use set, will time out, anyway, can not use the STL

Emm

Just use the trie tree to number it.

#include <iostream>#include<cstdio>#include<sstream>#include<cstring>#include<map>#include<cctype>#include<Set>#include<vector>#include<stack>#include<queue>#include<algorithm>#include<cmath>#include<bitset>#defineRap (i, A, n) for (int i=a; i<=n; i++)#defineRep (I, A, n) for (int i=a; i<n; i++)#defineLap (I, a, n) for (int i=n; i>=a; i--)#defineLEP (i, A, n) for (int i=n; i>a; i--)#defineRD (a) scanf ("%d", &a)#defineRlld (a) scanf ("%lld", &a)#defineRC (a) scanf ("%c", &a)#defineRS (a) scanf ("%s", a)#definePD (a) printf ("%d\n", a);#definePlld (a) printf ("%lld\n", a);#definePC (a) printf ("%c\n", a);#definePS (a) printf ("%s\n", a);#defineMOD 2018#defineLL Long Long#defineULL unsigned long Long#definePair Pair<int, int>#defineMem (A, B) memset (A, B, sizeof (a))#define_ Ios_base::sync_with_stdio (0), Cin.tie (0)//freopen ("1.txt", "R", stdin);using namespacestd;Const intMAXN =500010, INF =0x7fffffff, Ll_inf =0x7fffffffffffffff;CharSTR1[MAXN], STR2[MAXN];intRT, ans, tot;intF[MAXN], DEG[MAXN];intTRIE[MAXN <<1][ -], VIS[MAXN <<1];//map<string, int> vis;Set<int>SS;intFindintx) {    returnF[X] = = x? x: (F[x] =find (F[x]));}voidinit () { for(inti =0; i < MAXN; i++) F[i] =i; Tot= ans =0; Mem (deg,0);}intBuildChar*s) {    intLen =strlen (s); RT=0;  for(inti =0; i < Len; i++)    {        intx = S[i]-'a'; if(Trie[rt][x] = =0) Trie[rt][x] = + +tot; RT=Trie[rt][x]; }    if(!vis[rt]) vis[rt] = + +ans; returnvis[rt];}intMain () {init (); intu, v; intCNT =0;  while(SCANF ("%s%s", STR1, str2)! =EOF) {u=build (STR1); V=build (STR2); Deg[u]++; DEG[V]++; intL =find (U); intR =Find (v); if(l! = r) F[l] =R; }    intAter = Find (1); intFlag =0, Cnt1 =0, Cnt2 =0;  for(inti =1; I <= ans; i++)    {        intx =find (i); if(X! =ater) {printf ("impossible\n"); return 0; }        if(Deg[i] &1) Cnt1++; }    if(Cnt1 = =0|| Cnt1 = =2) printf ("possible\n"); Elseprintf ("impossible\n"); return 0;}

Colored sticks POJ-2513 (trie tree Oralu)

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.