Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么是wrong answer,样例过了啊,谁来帮帮我啊!!!

Posted by ACJunKi at 2009-05-03 20:01:01 on Problem 2524
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator