标签:return range problem should ann family ace rip ++
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7791 Accepted Submission(s): 2676
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define esp 0.00000000001 const int N=1e5+10,M=1e6+10,inf=1e9; const ll INF=1e18+10; int fa[110],du[110],flag[110]; int Find(int x) { return x==fa[x]?x:fa[x]=Find(fa[x]); } void update(int u,int v) { int x=Find(u); int y=Find(v); if(x!=y) { fa[x]=y; } } void init() { for(int i=0;i<=30;i++) fa[i]=i; memset(du,0,sizeof(du)); memset(flag,0,sizeof(flag)); } char a[N]; int main() { int T; scanf("%d",&T); while(T--) { init(); int n,p=-1; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%s",a); int u=a[0]-‘a‘+1; int v=a[strlen(a)-1]-‘a‘+1; update(u,v); du[u]++; du[v]--; flag[u]++; flag[v]++; } int ans1=0,ans2=0; for(int i=1;i<=26;i++) { if(!flag[i]) continue; if(du[i]==0) { if(p==-1) p=Find(i); if(Find(i)!=p) { ans1=-1; break; } } if(du[i]==-1) ans1++; if(du[i]==1) ans2++; if(du[i]<=-2||du[i]>=2) { ans1=-1; break; } } if((ans1==0&&ans2==0)||(ans1==1&&ans2==1)) printf("Ordering is possible.\n"); else printf("The door cannot be opened.\n"); } return 0; }
hdu 1116 Play on Words 欧拉路径+并查集
标签:return range problem should ann family ace rip ++
原文地址:http://www.cnblogs.com/jhz033/p/6114605.html