답안 #806299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
806299 2023-08-04T05:46:02 Z NekoRolly Monthly railway pass (LMIO18_menesinis_bilietas) C++17
100 / 100
174 ms 37460 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+4;

struct Dsu
{
    int rt[N],h[N],sz[N];

    void build(int n){
        for (int i=1; i<=n; i++){
            h[i] = 1, sz[i] = 1;
            rt[i] = i;
        }
    }

    int find(int a){
        if (a == rt[a]) return a;
        return rt[a] = find(rt[a]);
    }

    void join(int a,int b){
        a = find(a), b = find(b);
        if (a == b) return;
        if (h[a] > h[b]){
            swap(a, b);
        }
        h[b] += (h[a] == h[b]);
        sz[b] += sz[a];
        rt[a] = b;
    }
};

int n,m;
int cnt,ans;
Dsu d;
int Ed_n;
int Ed_a[N],Ed_b[N];
vector<int> adj[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;

    d.build(n);

    for (int i=0; i<m; i++){
        int a,b;
        char c;
        cin >> a >> b >> c;
        if (c == 'T'){
            d.join(a, b);
        }
        if (c == 'A'){
            Ed_a[Ed_n] = a;
            Ed_b[Ed_n] = b;
            Ed_n++;
        }
    }

    for (int i=0; i<Ed_n; i++){
        int a = d.find(Ed_a[i]);
        int b = d.find(Ed_b[i]);
        if (a == b) continue;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for (int i=1; i<=n; i++){
        if (i != d.find(i)) continue;
        vector<int> & v = adj[i];
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        cnt++;
    }

    // cout << "cnt : " << cnt << "\n";

    for (int i=1; i<=n; i++){
        if (i != d.find(i)) continue;
        if (adj[i].size() + 1 == cnt){
            ans += d.sz[i];
        }
    }

    cout << ans << "\n";

    return 0;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:83:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   83 |         if (adj[i].size() + 1 == cnt){
      |             ~~~~~~~~~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 18384 KB Output is correct
2 Correct 6 ms 12076 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 11 ms 17576 KB Output is correct
5 Correct 6 ms 12240 KB Output is correct
6 Correct 36 ms 14452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 17576 KB Output is correct
2 Correct 6 ms 12240 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 7 ms 12120 KB Output is correct
5 Correct 8 ms 12244 KB Output is correct
6 Correct 93 ms 22320 KB Output is correct
7 Correct 174 ms 37460 KB Output is correct
8 Correct 13 ms 13012 KB Output is correct
9 Correct 14 ms 13428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12076 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 7 ms 12120 KB Output is correct
5 Correct 8 ms 12244 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 12076 KB Output is correct
8 Correct 7 ms 12116 KB Output is correct
9 Correct 7 ms 12244 KB Output is correct
10 Correct 10 ms 12372 KB Output is correct
11 Correct 8 ms 12212 KB Output is correct
12 Correct 6 ms 12072 KB Output is correct
13 Correct 6 ms 12116 KB Output is correct
14 Correct 8 ms 12340 KB Output is correct
15 Correct 6 ms 12068 KB Output is correct
16 Correct 7 ms 12116 KB Output is correct
17 Correct 6 ms 11988 KB Output is correct
18 Correct 6 ms 12116 KB Output is correct
19 Correct 6 ms 12116 KB Output is correct
20 Correct 7 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 12076 KB Output is correct
3 Correct 7 ms 12116 KB Output is correct
4 Correct 7 ms 12244 KB Output is correct
5 Correct 10 ms 12372 KB Output is correct
6 Correct 8 ms 12212 KB Output is correct
7 Correct 6 ms 12072 KB Output is correct
8 Correct 6 ms 12116 KB Output is correct
9 Correct 8 ms 12340 KB Output is correct
10 Correct 6 ms 12068 KB Output is correct
11 Correct 7 ms 12116 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12116 KB Output is correct
14 Correct 6 ms 12116 KB Output is correct
15 Correct 7 ms 12116 KB Output is correct
16 Correct 6 ms 12076 KB Output is correct
17 Correct 6 ms 11988 KB Output is correct
18 Correct 6 ms 11988 KB Output is correct
19 Correct 7 ms 12120 KB Output is correct
20 Correct 8 ms 12244 KB Output is correct
21 Correct 6 ms 12240 KB Output is correct
22 Correct 13 ms 13012 KB Output is correct
23 Correct 14 ms 13428 KB Output is correct
24 Correct 36 ms 14452 KB Output is correct
25 Correct 15 ms 12924 KB Output is correct
26 Correct 79 ms 21620 KB Output is correct
27 Correct 36 ms 16512 KB Output is correct
28 Correct 49 ms 18164 KB Output is correct
29 Correct 36 ms 15564 KB Output is correct
30 Correct 44 ms 16972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 12076 KB Output is correct
3 Correct 7 ms 12116 KB Output is correct
4 Correct 7 ms 12244 KB Output is correct
5 Correct 10 ms 12372 KB Output is correct
6 Correct 8 ms 12212 KB Output is correct
7 Correct 6 ms 12072 KB Output is correct
8 Correct 6 ms 12116 KB Output is correct
9 Correct 8 ms 12340 KB Output is correct
10 Correct 6 ms 12068 KB Output is correct
11 Correct 7 ms 12116 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12116 KB Output is correct
14 Correct 6 ms 12116 KB Output is correct
15 Correct 7 ms 12116 KB Output is correct
16 Correct 15 ms 12924 KB Output is correct
17 Correct 79 ms 21620 KB Output is correct
18 Correct 36 ms 16512 KB Output is correct
19 Correct 49 ms 18164 KB Output is correct
20 Correct 36 ms 15564 KB Output is correct
21 Correct 44 ms 16972 KB Output is correct
22 Correct 97 ms 18384 KB Output is correct
23 Correct 6 ms 12076 KB Output is correct
24 Correct 6 ms 11988 KB Output is correct
25 Correct 11 ms 17576 KB Output is correct
26 Correct 6 ms 11988 KB Output is correct
27 Correct 7 ms 12120 KB Output is correct
28 Correct 8 ms 12244 KB Output is correct
29 Correct 6 ms 12240 KB Output is correct
30 Correct 93 ms 22320 KB Output is correct
31 Correct 174 ms 37460 KB Output is correct
32 Correct 13 ms 13012 KB Output is correct
33 Correct 14 ms 13428 KB Output is correct
34 Correct 36 ms 14452 KB Output is correct
35 Correct 20 ms 13928 KB Output is correct
36 Correct 108 ms 22580 KB Output is correct
37 Correct 53 ms 17288 KB Output is correct