Submission #673309

# Submission time Handle Problem Language Result Execution time Memory
673309 2022-12-20T07:11:16 Z haxorman Traffic (CEOI11_tra) C++14
8 / 100
1044 ms 84752 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 3e5 + 7;

int n, m, A, B, vis[mxN], vis_cnt = 1, dp[mxN], east[mxN];
bool used[mxN];
vector<pair<int,int>> west;
vector<int> graph[mxN], rev[mxN], scc[mxN], order, cmp;
void dfs1(int u) {
    vis[u] = vis_cnt;
    for (auto v : graph[u]) {
        if (vis[v] != vis_cnt) {
            dfs1(v);
        }
    }
    order.push_back(u);
}
void dfs2(int u) {
    vis[u] = vis_cnt;
    cmp.push_back(u);
    for (auto v : rev[u]) {
        if (vis[v] != vis_cnt) {
            dfs2(v);
        }
    }
}
int dfs(int u) {
    if (vis[u] == vis_cnt) {
        return 0;
    }
    if (dp[u] != -1) {
        return dp[u];
    }
    vis[u] = vis_cnt;
    dp[u] = east[u];
    for (auto v : scc[u]) {
        dp[u] += dfs(v);
    }
    return dp[u];
}
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n >> m >> A >> B;
    map<pair<int,int>,int> pos;
    for (int i = 1; i <= n; ++i) {
        int x, y;
        cin >> x >> y;
        pos[{x, y}] = i;
        if (!x) {
            west.push_back({x, y});
        }
        else if (x == A) {
            east[i] = 1;
        }
    }
    for (int i = 0; i < m; ++i) {
        int u, v, d;
        cin >> u >> v >> d;
        graph[u].push_back(v);
        rev[v].push_back(u);
        if (d == 2) {
            graph[v].push_back(v);
            rev[u].push_back(v);
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (vis[i] != vis_cnt) {
            dfs1(i);
        }
    }
    ++vis_cnt;
    reverse(order.begin(), order.end());
    vector<int> p(n + 1), roots;
    for (auto u : order) {
        if (vis[u] != vis_cnt) {
            dfs2(u);
            int root = cmp.back();
            p[root] = root;
            for (auto v : cmp) {
                p[v] = root;
            }
            roots.push_back(root);
            cmp.clear();
        }
    }
    ++vis_cnt;
    for (int u = 1; u <= n; ++u) {
        if (p[u] != u) {
            east[p[u]] += east[u];
        }
        for (auto v : graph[u]) {
            if (p[u] != p[v]) {
                scc[p[u]].push_back(p[v]);
            }
        }
    }
    memset(dp, -1, sizeof(dp));
    sort(west.begin(), west.end(), greater<pair<int,int>>());
    for (auto x : west) {
        int res = dfs(p[pos[x]]);
        cout << res << "\n";
        ++vis_cnt;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 22612 KB Output is correct
2 Correct 10 ms 22612 KB Output is correct
3 Correct 13 ms 22576 KB Output is correct
4 Correct 11 ms 22612 KB Output is correct
5 Correct 11 ms 22612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 22612 KB Output is correct
2 Incorrect 11 ms 22644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 22612 KB Output is correct
2 Incorrect 13 ms 22752 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 23008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 27124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 30292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 120 ms 38088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 177 ms 40148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 358 ms 52636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 610 ms 71672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1044 ms 84752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 367 ms 62940 KB Output isn't correct
2 Halted 0 ms 0 KB -