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 |
动态数组总是RE,求问牛们为什么?#include<iostream> #include<cstdio> using namespace std; int **s;//改为s[100010][2]是可以过的 int find_set(int x) { if(x==s[x][0]) return x; else s[x][0]=find_set(s[x][0]); return s[x][0]; } void link(int x,int y) { if(find_set(x)==find_set(y)) return; s[find_set(x)][0]=find_set(y); } int main() { int i,T,N,M,a,b; char ch; scanf("%d",&T); while(T--) { scanf("%d%d",&N,&M); s=new int *[N+1]; for(i=0;i<=N;i++) s[i]=new int[2]; for(i=1;i<=N;i++) { s[i][0]=i; s[i][1]=0; } while(M--) { scanf("\n%c%d%d",&ch,&a,&b); if(ch=='D') { if(s[a][1]) link(s[a][1],b); s[a][1]=b; if(s[b][1]) link(s[b][1],a); s[b][1]=a; } else if(ch=='A') { if(find_set(a)==find_set(b)) printf("In the same gang.\n"); else { if(find_set(s[a][1])==find_set(b)) printf("In different gangs.\n"); else printf("Not sure yet.\n"); } } } for(i=0;i<=N;i++) delete [] s[i]; delete [] s; s=NULL; } return 0; } 是什么地方越界了吗,实在是想不到... Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator