ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1272. Non-Yekaterinburg Subway

Why do I get WA on test 14?
Posted by Kalina_Petrova 12 Apr 2008 21:04
I count the components of the graph without reading the bridges.The answer is the amount of the components minus one.I think my algorithm is correct.So why do I get WA on 14 test?Here is my source :


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,r,w,k,m,i,j,x,y,br=0;
    int a[10006];
    scanf("%d %d %d",&n,&k,&m);
    for(i=1;i<=n;i++)
    a[i]=i;
    for(i=1;i<=k;i++)
    {
        scanf("%d %d",&x,&y);
        if(a[x]==a[y])continue;
        for(j=1;j<=n;j++)
        if(a[j]==x)a[j]=y;
    }
    sort(a,a+n);
    for(i=1;i<n;i++)
    if(a[i]!=a[i+1])br++;
    printf("%d\n",br);
}

Can you help me please?
I found my mistake
Posted by Kalina_Petrova 12 Apr 2008 21:33
That's OK, I found my mistake.It was just a stupid mistake in the source.However, thanks!