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 1160. Network

Why WA?
Posted by Andriy Kozachuk(VNTU) 22 Jul 2008 16:19
Help me please.
I can't find error
this is my code:
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int i;
    vector<pair<int,pair<int,int> > >a(m);
    vector<int>c(n);
    for(i=0;i<m;i++)
        cin>>a[i].second.first>>a[i].second.second>>a[i].first;
    for(i=0;i<n;i++)
        c[i]=i;

    sort(a.begin(),a.end());
    int kil=n;
    int pot=0;
    while(kil>1){
        if(c[a[pot].second.first]!=c[a[pot].second.second]){
            int c2=c[a[pot].second.second];
            int c1=c[a[pot].second.first];
            for(i=0;i<n;i++)
                if(c[i]==c2)
                    c[i]=c1;
            kil--;
        }
        pot++;
    }
    cout<<a[pot-1].first<<endl;
    cout<<pot<<endl;
    for(i=0;i<pot;i++)
        cout<<a[i].second.first<<' '<<a[i].second.second<<endl;
    return 0;
}

Edited by author 22.07.2008 16:20