Submission #921190

# Submission time Handle Problem Language Result Execution time Memory
921190 2024-02-03T12:38:54 Z zhehan Monthly railway pass (LMIO18_menesinis_bilietas) C++14
16 / 100
1564 ms 191444 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){
        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(e.second.size()>=mf.size()){
            counter+=cc[e.first];
        }
    }
    cout<<counter;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 291 ms 25940 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 432 ms 136768 KB Output is correct
5 Correct 6 ms 3932 KB Output is correct
6 Correct 87 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 432 ms 136768 KB Output is correct
2 Correct 6 ms 3932 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 6 ms 1628 KB Output is correct
6 Correct 459 ms 55840 KB Output is correct
7 Correct 1564 ms 191444 KB Output is correct
8 Correct 23 ms 7256 KB Output is correct
9 Correct 35 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 6 ms 1628 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 6 ms 604 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 7 ms 888 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Incorrect 1 ms 372 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 6 ms 604 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 7 ms 888 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Incorrect 1 ms 372 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 6 ms 604 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 7 ms 888 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Incorrect 1 ms 372 KB Output isn't correct
15 Halted 0 ms 0 KB -