Submission #921189

# Submission time Handle Problem Language Result Execution time Memory
921189 2024-02-03T12:38:16 Z zhehan Monthly railway pass (LMIO18_menesinis_bilietas) C++14
16 / 100
1421 ms 194512 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(mf.size()<=e.second.size()){
            counter+=cc[e.first];
        }
    }
    cout<<counter;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 320 ms 30320 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 424 ms 136372 KB Output is correct
5 Correct 6 ms 3932 KB Output is correct
6 Correct 81 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 424 ms 136372 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 7 ms 1628 KB Output is correct
6 Correct 474 ms 58648 KB Output is correct
7 Correct 1421 ms 194512 KB Output is correct
8 Correct 24 ms 7508 KB Output is correct
9 Correct 42 ms 9400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 7 ms 1628 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 584 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 6 ms 856 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 8 ms 1116 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Incorrect 1 ms 344 KB Output isn't correct
20 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 584 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 6 ms 856 KB Output is correct
6 Correct 5 ms 860 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 444 KB Output is correct
9 Correct 8 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 856 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Incorrect 1 ms 344 KB Output isn't correct
15 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 584 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 6 ms 856 KB Output is correct
6 Correct 5 ms 860 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 444 KB Output is correct
9 Correct 8 ms 1116 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 856 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Incorrect 1 ms 344 KB Output isn't correct
15 Halted 0 ms 0 KB -