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 |
为什么是wrong answer,样例过了啊,谁来帮帮我啊!!!#include <iostream> #include <cstdlib> using namespace std; int main() { int n,m;int p(1); while(scanf("%d%d",&n,&m)&&n!=0&&m!=0) { int sum(0);int c(1); int *a=(int *)malloc(m*sizeof(int)); int *b=(int *)malloc(m*sizeof(int)); int i; for(i=0;i<m;i++) scanf("%d%d",&a[i],&b[i]); int *w=(int *)malloc((n+1)*sizeof(int)); for(i=0;i<n+1;i++) w[i]=0; for(i=0;i<m;i++) { if(w[a[i]]==0&&w[b[i]]==0) {w[a[i]]=w[b[i]]=c;c++;} if(w[a[i]]!=0) {w[b[i]]=w[a[i]];} if(w[b[i]]!=0) {w[a[i]]=w[b[i]];} } for(i=1;i<n+1;i++) if(w[i]==0) sum++; sum+=(--c); printf("Case %d: %d\n",p,sum);p++; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator