Submission #920869

# Submission time Handle Problem Language Result Execution time Memory
920869 2024-02-03T06:47:53 Z Sandarach151 Monthly railway pass (LMIO18_menesinis_bilietas) C++17
100 / 100
580 ms 90656 KB
#include<bits/stdc++.h>
using namespace std;

vector<int> link;
vector<int> sizes;

int find(int x){
    while(x!=link[x]) x = link[x];
    return x;
}

bool same(int a, int b){
    return find(a)==find(b);
}

void unite(int a, int b){
    a = find(a);
    b = find(b);
    if(a!=b){
        if(sizes[a]<sizes[b]) swap(a, b);
        link[b] = a;
        sizes[a] += sizes[b];
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<pair<int, bool> > adg[n];
    vector<pair<int, int> > bus;
    link.resize(n);
    sizes.resize(n);
    int newsize[n];
    for(int i=0; i<n; i++){
        link[i]=i;
        sizes[i]=1;
        newsize[i]=0;
    }
    for(int i=0; i<m; i++){
        int a, b;
        char t;
        cin >> a >> b >> t;
        a--;
        b--;
        adg[a].push_back(make_pair(b, (t=='T')));
        adg[b].push_back(make_pair(a, (t=='T')));
        if(t=='T') unite(a, b);
        else bus.push_back(make_pair(a, b));
    }
    set<int> newgraph[n];
    for(auto u : bus){
        if(find(u.first)!=find(u.second)){
            if(newgraph[find(u.first)].count(find(u.second))==0){
                newsize[find(u.first)]+=sizes[find(u.second)];
                newsize[find(u.second)]+=sizes[find(u.first)];
                newgraph[find(u.first)].insert(find(u.second));
                newgraph[find(u.second)].insert(find(u.first));
            }
        }
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        if(newsize[i]+sizes[i]==n){
            ans+=sizes[i];
        }
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 230 ms 39764 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 24 ms 39004 KB Output is correct
5 Correct 1 ms 1368 KB Output is correct
6 Correct 37 ms 5796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 39004 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 499 ms 45120 KB Output is correct
7 Correct 580 ms 90656 KB Output is correct
8 Correct 8 ms 3676 KB Output is correct
9 Correct 16 ms 5336 KB Output is correct
# 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 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 3 ms 860 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 4 ms 1372 KB Output is correct
21 Correct 1 ms 1368 KB Output is correct
22 Correct 8 ms 3676 KB Output is correct
23 Correct 16 ms 5336 KB Output is correct
24 Correct 37 ms 5796 KB Output is correct
25 Correct 7 ms 1496 KB Output is correct
26 Correct 114 ms 13968 KB Output is correct
27 Correct 34 ms 6348 KB Output is correct
28 Correct 164 ms 17900 KB Output is correct
29 Correct 28 ms 4560 KB Output is correct
30 Correct 115 ms 16484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 3 ms 860 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 7 ms 1496 KB Output is correct
17 Correct 114 ms 13968 KB Output is correct
18 Correct 34 ms 6348 KB Output is correct
19 Correct 164 ms 17900 KB Output is correct
20 Correct 28 ms 4560 KB Output is correct
21 Correct 115 ms 16484 KB Output is correct
22 Correct 230 ms 39764 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 24 ms 39004 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 4 ms 1372 KB Output is correct
29 Correct 1 ms 1368 KB Output is correct
30 Correct 499 ms 45120 KB Output is correct
31 Correct 580 ms 90656 KB Output is correct
32 Correct 8 ms 3676 KB Output is correct
33 Correct 16 ms 5336 KB Output is correct
34 Correct 37 ms 5796 KB Output is correct
35 Correct 30 ms 6236 KB Output is correct
36 Correct 319 ms 27788 KB Output is correct
37 Correct 95 ms 23620 KB Output is correct