Submission #826868

# Submission time Handle Problem Language Result Execution time Memory
826868 2023-08-16T05:36:19 Z IBory Traffic (CEOI11_tra) C++17
100 / 100
620 ms 43396 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;

const int MAX = 300003;
int X[MAX], Y[MAX], U[MAX], D[MAX];
bool V[MAX];
vector<int> G[MAX], RG[MAX];

void BFS(int* S, int st, int C) {
    S[st] = C;
    queue<int> Q;
    Q.push(st);
    while (!Q.empty()) {
        int cur = Q.front(); Q.pop();
        for (int next : RG[cur]) {
            if (S[next] != -1) continue;
            S[next] = C;
            Q.push(next);
        }
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int N, M, A, B;
    cin >> N >> M >> A >> B;
    for (int i = 1; i <= N; ++i) cin >> X[i] >> Y[i];
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        G[a].push_back(b);
        RG[b].push_back(a);
        if (c == 2) {
            G[b].push_back(a);
            RG[a].push_back(b);
        }
    }

    vector<pii> L, R;
    for (int i = 1; i <= N; ++i) {
        if (X[i] == 0) L.emplace_back(Y[i], i);
    }
    sort(L.begin(), L.end(), greater<pii>());

    queue<int> Q;
    for (auto [_, n] : L) {
        V[n] = 1;
        Q.push(n);
    }
    while (!Q.empty()) {
        int cur = Q.front(); Q.pop();
        for (int next : G[cur]) {
            if (V[next]) continue;
            V[next] = 1;
            Q.push(next);
        }
    }
    for (int i = 1; i <= N; ++i) {
        if (X[i] == A && V[i]) R.emplace_back(Y[i], i);
    }
    sort(R.begin(), R.end(), greater<pii>());

    memset(U, 0xff, sizeof(U));
    memset(D, 0xff, sizeof(D));
    for (int i = 0; i < R.size(); ++i) {
        auto [_, n] = R[i];
        BFS(U, n, i);
    }
    for (int i = R.size() - 1; i >= 0; --i) {
        auto [_, n] = R[i];
        BFS(D, n, i);
    }

    for (auto [_, n] : L) {
        int ans = (D[n] == -1 ? 0 : D[n] - U[n] + 1);
        cout << ans << '\n';
    }
    return 0;
}

Compilation message

tra.cpp: In function 'int main()':
tra.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for (int i = 0; i < R.size(); ++i) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16724 KB Output is correct
2 Correct 8 ms 16716 KB Output is correct
3 Correct 8 ms 16720 KB Output is correct
4 Correct 7 ms 16724 KB Output is correct
5 Correct 8 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16724 KB Output is correct
2 Correct 10 ms 16676 KB Output is correct
3 Correct 8 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16724 KB Output is correct
2 Correct 8 ms 16724 KB Output is correct
3 Correct 8 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16864 KB Output is correct
2 Correct 10 ms 17236 KB Output is correct
3 Correct 9 ms 17120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 17928 KB Output is correct
2 Correct 60 ms 20404 KB Output is correct
3 Correct 24 ms 18860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 19648 KB Output is correct
2 Correct 53 ms 21224 KB Output is correct
3 Correct 33 ms 20456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 21852 KB Output is correct
2 Correct 71 ms 23976 KB Output is correct
3 Correct 112 ms 24468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 23568 KB Output is correct
2 Correct 79 ms 23980 KB Output is correct
3 Correct 110 ms 24864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 26776 KB Output is correct
2 Correct 177 ms 28880 KB Output is correct
3 Correct 337 ms 30844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 31972 KB Output is correct
2 Correct 296 ms 35820 KB Output is correct
3 Correct 270 ms 32280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 598 ms 43396 KB Output is correct
2 Correct 341 ms 37796 KB Output is correct
3 Correct 524 ms 39920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 25872 KB Output is correct
2 Correct 404 ms 38188 KB Output is correct
3 Correct 442 ms 37836 KB Output is correct
4 Correct 620 ms 42140 KB Output is correct