답안 #373787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373787 2021-03-05T18:44:25 Z gustason Monthly railway pass (LMIO18_menesinis_bilietas) C++11
100 / 100
773 ms 125004 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxN = 5e5 + 5;
vector<int> adj[maxN];
bool vis[maxN];

int parent[maxN];
int sz[maxN];
int find(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find(parent[v]);
}
void unite(int a, int b) {
    a = find(a), b = find(b);

    if (a == b)
        return;
    if (sz[a] < sz[b])
        swap(a, b);

    parent[b] = a;
    sz[a] += sz[b];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        parent[i] = i;
        sz[i] = 1;
    }

    for(int i = 0; i < m; i++) {
        char c;
        int a, b;
        cin >> a >> b >> c;
        if (c == 'T') {
            unite(a, b);
        } else {
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
    }

    set<int> s;
    for(int i = 1; i <= n; i++) {
        parent[i] = find(i);
    }
    for(int i = 1; i <= n; i++) {
        s.insert(parent[i]);
    }


    set<int> ls[n+1];
    int comp = s.size();
    for(int i = 1; i <= n; i++) {
        ls[parent[i]].insert(parent[i]);
        for(int j : adj[i]) {
            ls[parent[i]].insert(parent[j]);
        }
    }


    int ans = 0;
    for(int i = 0; i <= n; i++) {
        ans += ((int) ls[parent[i]].size() >= comp);
    }
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 28652 KB Output is correct
2 Correct 8 ms 12140 KB Output is correct
3 Correct 9 ms 12140 KB Output is correct
4 Correct 166 ms 82148 KB Output is correct
5 Correct 12 ms 14080 KB Output is correct
6 Correct 50 ms 13688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 82148 KB Output is correct
2 Correct 12 ms 14080 KB Output is correct
3 Correct 10 ms 12140 KB Output is correct
4 Correct 9 ms 12268 KB Output is correct
5 Correct 12 ms 13036 KB Output is correct
6 Correct 272 ms 53972 KB Output is correct
7 Correct 773 ms 125004 KB Output is correct
8 Correct 23 ms 16364 KB Output is correct
9 Correct 34 ms 17772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 9 ms 12140 KB Output is correct
3 Correct 10 ms 12140 KB Output is correct
4 Correct 9 ms 12268 KB Output is correct
5 Correct 12 ms 13036 KB Output is correct
6 Correct 8 ms 12140 KB Output is correct
7 Correct 9 ms 12140 KB Output is correct
8 Correct 9 ms 12140 KB Output is correct
9 Correct 10 ms 12268 KB Output is correct
10 Correct 12 ms 12396 KB Output is correct
11 Correct 11 ms 12524 KB Output is correct
12 Correct 9 ms 12140 KB Output is correct
13 Correct 9 ms 12160 KB Output is correct
14 Correct 15 ms 12780 KB Output is correct
15 Correct 9 ms 12140 KB Output is correct
16 Correct 9 ms 12140 KB Output is correct
17 Correct 8 ms 12140 KB Output is correct
18 Correct 9 ms 12268 KB Output is correct
19 Correct 9 ms 12140 KB Output is correct
20 Correct 10 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 9 ms 12140 KB Output is correct
3 Correct 9 ms 12140 KB Output is correct
4 Correct 10 ms 12268 KB Output is correct
5 Correct 12 ms 12396 KB Output is correct
6 Correct 11 ms 12524 KB Output is correct
7 Correct 9 ms 12140 KB Output is correct
8 Correct 9 ms 12160 KB Output is correct
9 Correct 15 ms 12780 KB Output is correct
10 Correct 9 ms 12140 KB Output is correct
11 Correct 9 ms 12140 KB Output is correct
12 Correct 8 ms 12140 KB Output is correct
13 Correct 9 ms 12268 KB Output is correct
14 Correct 9 ms 12140 KB Output is correct
15 Correct 10 ms 12268 KB Output is correct
16 Correct 8 ms 12140 KB Output is correct
17 Correct 9 ms 12140 KB Output is correct
18 Correct 10 ms 12140 KB Output is correct
19 Correct 9 ms 12268 KB Output is correct
20 Correct 12 ms 13036 KB Output is correct
21 Correct 12 ms 14080 KB Output is correct
22 Correct 23 ms 16364 KB Output is correct
23 Correct 34 ms 17772 KB Output is correct
24 Correct 50 ms 13688 KB Output is correct
25 Correct 19 ms 12908 KB Output is correct
26 Correct 148 ms 22124 KB Output is correct
27 Correct 58 ms 15596 KB Output is correct
28 Correct 120 ms 28012 KB Output is correct
29 Correct 48 ms 15212 KB Output is correct
30 Correct 132 ms 26440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 9 ms 12140 KB Output is correct
3 Correct 9 ms 12140 KB Output is correct
4 Correct 10 ms 12268 KB Output is correct
5 Correct 12 ms 12396 KB Output is correct
6 Correct 11 ms 12524 KB Output is correct
7 Correct 9 ms 12140 KB Output is correct
8 Correct 9 ms 12160 KB Output is correct
9 Correct 15 ms 12780 KB Output is correct
10 Correct 9 ms 12140 KB Output is correct
11 Correct 9 ms 12140 KB Output is correct
12 Correct 8 ms 12140 KB Output is correct
13 Correct 9 ms 12268 KB Output is correct
14 Correct 9 ms 12140 KB Output is correct
15 Correct 10 ms 12268 KB Output is correct
16 Correct 19 ms 12908 KB Output is correct
17 Correct 148 ms 22124 KB Output is correct
18 Correct 58 ms 15596 KB Output is correct
19 Correct 120 ms 28012 KB Output is correct
20 Correct 48 ms 15212 KB Output is correct
21 Correct 132 ms 26440 KB Output is correct
22 Correct 150 ms 28652 KB Output is correct
23 Correct 8 ms 12140 KB Output is correct
24 Correct 9 ms 12140 KB Output is correct
25 Correct 166 ms 82148 KB Output is correct
26 Correct 10 ms 12140 KB Output is correct
27 Correct 9 ms 12268 KB Output is correct
28 Correct 12 ms 13036 KB Output is correct
29 Correct 12 ms 14080 KB Output is correct
30 Correct 272 ms 53972 KB Output is correct
31 Correct 773 ms 125004 KB Output is correct
32 Correct 23 ms 16364 KB Output is correct
33 Correct 34 ms 17772 KB Output is correct
34 Correct 50 ms 13688 KB Output is correct
35 Correct 49 ms 17152 KB Output is correct
36 Correct 370 ms 33260 KB Output is correct
37 Correct 92 ms 26476 KB Output is correct