Submission #920997

# Submission time Handle Problem Language Result Execution time Memory
920997 2024-02-03T08:44:58 Z zhehan Monthly railway pass (LMIO18_menesinis_bilietas) C++14
16 / 100
1327 ms 181240 KB
#include <bits/stdc++.h>

using namespace std;

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);
}

int 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){
        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){
        if(mf.size()==e.second.size()){
            counter+=cc[e.first];
        }
    }
    cout<<counter;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 289 ms 24680 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 416 ms 127312 KB Output is correct
5 Correct 6 ms 3676 KB Output is correct
6 Correct 81 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 416 ms 127312 KB Output is correct
2 Correct 6 ms 3676 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 6 ms 1372 KB Output is correct
6 Correct 430 ms 50832 KB Output is correct
7 Correct 1327 ms 181240 KB Output is correct
8 Correct 23 ms 7092 KB Output is correct
9 Correct 36 ms 8416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 6 ms 1372 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Incorrect 6 ms 600 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Incorrect 6 ms 600 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Incorrect 6 ms 600 KB Output isn't correct
6 Halted 0 ms 0 KB -