답안 #373773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373773 2021-03-05T17:46:03 Z gustason Monthly railway pass (LMIO18_menesinis_bilietas) C++11
6 / 100
708 ms 55408 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxN = 5e5 + 5;
vector<int> adj[maxN];
bool ok[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];
}
void dfs(int v) {
    vis[v] = true;
    for(int u : adj[v]) {
        ok[v] |= ok[u];
        if (!vis[u]) {
            dfs(u);
        }
    }
}
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++) {
        s.insert(parent[i]);
    }


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

        int sum = s.size();
        if (sum == comp) {
            ok[i] = true;
        }
    }

    for(int i = 1; i <= n; i++) {
        ok[parent[i]] |= ok[i];
    }
    for(int i = 1; i <= n; i++) {
        ok[i] |= ok[parent[i]];
    }

    int ans = 0;
    for(int i = 0; i <= n; i++) {
        ans += ok[i];
    }
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 160 ms 23020 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 38252 KB Output is correct
2 Correct 9 ms 12140 KB Output is correct
3 Correct 9 ms 12140 KB Output is correct
4 Correct 13 ms 12268 KB Output is correct
5 Correct 11 ms 12908 KB Output is correct
6 Correct 243 ms 22996 KB Output is correct
7 Correct 708 ms 55408 KB Output is correct
8 Correct 21 ms 13676 KB Output is correct
9 Correct 27 ms 13932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12140 KB Output is correct
2 Correct 9 ms 12140 KB Output is correct
3 Correct 13 ms 12268 KB Output is correct
4 Correct 8 ms 12140 KB Output is correct
5 Correct 8 ms 12140 KB Output is correct
6 Incorrect 9 ms 12140 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 8 ms 12140 KB Output is correct
3 Incorrect 9 ms 12140 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 8 ms 12140 KB Output is correct
3 Incorrect 9 ms 12140 KB Output isn't correct
4 Halted 0 ms 0 KB -