Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
请高手们看看我的代码~~~为什么总是超时呢???????????#include <iostream> using namespace std; #define max 100010 int father[max],num[max]; void makeset(int n) { for(int i=0;i<n;i++) { father[i]=i; num[i]=0; } } int findset(int x) { if(father[x]!=x) father[x]=findset(father[x]); return father[x]; } void um(int a,int b) { int c=findset(a); int d=findset(b); father[c]=d; num[b]=findset(num[a]); } int main() { int t,n,a,b,m; char ca; cin>>t; for(int j=0;j<t;j++) { cin>>n>>m; makeset(n); for(int u=0;u<m;u++) { cin>>ca>>a>>b; if(ca=='D') { if(num[a]!=0) um(num[a],b); else if(num[b]!=0) um(num[b],a); else { num[a]=b; num[b]=a; } } else { if(findset(a)==findset(b)) cout<<"In the same gang."<<endl; else { if(num[a]!=0&&num[b]!=0) cout<<"In different gangs."<<endl; else cout<<"Not sure yet."<<endl; } } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator