Submission #921043

# Submission time Handle Problem Language Result Execution time Memory
921043 2024-02-03T09:06:41 Z zhehan Monthly railway pass (LMIO18_menesinis_bilietas) C++14
0 / 100
495 ms 140500 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int parent[500000];

int f(int a){
    if(parent[a]==a){
        return a;
    }
    return parent[a]=f(parent[a]);
}

void u(int a,int b){
    parent[f(a)]=f(b);
}

signed main()
{
    int n,m;
    cin>>n>>m;
    for(int i{1};i<n+1;++i){
        parent[i]=i;
    }
    map<int,vector<int>> ma;
    for(int i{};i<m;++i){
        int a,b;
        char c;
        cin>>a>>b>>c;
        if(c=='T'){
            u(a,b);
        }else{
            ma[a].push_back(b);
            ma[b].push_back(a);
        }
    }
    map<int,set<int>> mf;
    map<int,int> cc;
    for(int i{1};i<n+1;++i){
        cout<<f(i)<<'\n';
        cc[f(i)]++;
        mf[f(i)].insert(-1);
        for(auto e:ma[i]){
            mf[f(i)].insert(f(e));
        }
    }
    int counter=0;
    for(auto e:mf){
        cout<<e.second.size()<<'\n';
        if(mf.size()==e.second.size()){
            counter+=cc[e.first];
        }
    }
    cout<<counter;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 317 ms 28084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 495 ms 140500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -