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 |
有没有人想过不用并查集做?能给我个数据让我wa吗?#include<iostream> #include<cstdio> using namespace std; int n,m,kind[50005]; int main () { int times=0; cin>>n>>m; fill(kind,kind+n+2,0); for(int i=0;i<m;i++) { int d,a,b; cin>>d>>a>>b; if(a>n||b>n) { times++; continue; } if(d==1) { if(kind[a]==0&&kind[b]==0) { kind[a]=1; kind[b]=1; } if(kind[a]!=0&&kind[b]==0) kind[b]=kind[a]; if(kind[b]!=0&&kind[a]==0) kind[a]=kind[b]; if(kind[a]!=0&&kind[b]!=0&&kind[b]!=kind[a]) times++; } if(d==2) { if(kind[a]!=0&&kind[b]!=0) { if(kind[a]-kind[b]==-1||kind[a]-kind[b]==2) times=times; else times++; } if(kind[a]!=0&&kind[b]==0) if(kind[a]<=2) kind[b]=kind[a]+1; else kind[b]=kind[a]-2; if(kind[b]!=0&&kind[a]==0) if(kind[b]>=2) kind[a]=kind[b]-1; else kind[a]=kind[b]+2; if(kind[a]==0&&kind[b]==0) { kind[a]=1; kind[b]=2; } } } cout<<times<<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