Submission #67724

# Submission time Handle Problem Language Result Execution time Memory
67724 2018-08-15T09:10:31 Z aquablitz11 Toy Train (IOI17_train) C++14
23 / 100
1050 ms 26140 KB
#include <bits/stdc++.h>
#include "train.h"
using namespace std;

const int N = 5e5+10;
vector<int> G[N], R[N];

vector<int> who_wins(vector<int> A, vector<int> C, vector<int> U, vector<int> V)
{
    // input
    int n = A.size();
    int m = U.size();
    for (int i = 0; i < m; ++i) {
        G[U[i]].push_back(V[i]);
        R[V[i]].push_back(U[i]);
    }

    vector<int> ans(n, 0);
    for (int i = 0; i < n; ++i) if (C[i]) { // i = main recharger we need for cycle
        // first step: find all nodes that can be forced to reach i
        vector<bool> reach(n, false);
        vector<int> cnt(n, 0);
        queue<int> Q;
        Q.push(i);
        while (!Q.empty()) {
            int u = Q.front(); Q.pop();
            reach[u] = true;
            for (auto p : R[u]) if (!reach[p]) {
                ++cnt[p];
                if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size()))
                    Q.push(p);
            }
        }
        // second step: find all nodes that are part of i-cycle
        vector<bool> cycle(n, false);
        fill(cnt.begin(), cnt.end(), 0); // use as vis array
        Q.push(i);
        cnt[i] = 1;
        while (!Q.empty()) {
            int u = Q.front(); Q.pop();
            int cntr = 0;
            for (auto v : G[u]) if (reach[v]) ++cntr;
            if ((A[u] && cntr > 0) || (!A[u] && cntr == G[u].size())) {
                cycle[u] = true;
                for (auto v : G[u]) if (!cnt[v]) {
                    cnt[v] = 1;
                    Q.push(v);
                }
            }
        }
        // third step: find all nodes that could reach the cycle
        fill(cnt.begin(), cnt.end(), 0);
        for (int u = 0; u < n; ++u) if (cycle[u])
            Q.push(u);
        while (!Q.empty()) {
            int u = Q.front(); Q.pop();
            cycle[u] = true;
            ans[u] = true;
            for (auto p : R[u]) if (!cycle[p]) {
                ++cnt[p];
                if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size()))
                    Q.push(p);
            }
        }
    }

    return ans;
}

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:30:63: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size()))
train.cpp:43:54: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if ((A[u] && cntr > 0) || (!A[u] && cntr == G[u].size())) {
                                                 ~~~~~^~~~~~~~~~~~~~
train.cpp:61:63: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size()))
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 24408 KB 3rd lines differ - on the 26th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 24408 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 107 ms 25128 KB Output is correct
2 Correct 175 ms 25340 KB Output is correct
3 Correct 215 ms 25568 KB Output is correct
4 Correct 1050 ms 25808 KB Output is correct
5 Correct 204 ms 25928 KB Output is correct
6 Correct 63 ms 26004 KB Output is correct
7 Correct 1002 ms 26076 KB Output is correct
8 Correct 34 ms 26076 KB Output is correct
9 Correct 36 ms 26076 KB Output is correct
10 Correct 35 ms 26076 KB Output is correct
11 Correct 35 ms 26076 KB Output is correct
12 Correct 33 ms 26076 KB Output is correct
13 Correct 40 ms 26104 KB Output is correct
14 Correct 37 ms 26104 KB Output is correct
15 Correct 37 ms 26128 KB Output is correct
16 Correct 33 ms 26128 KB Output is correct
17 Correct 38 ms 26128 KB Output is correct
18 Correct 278 ms 26128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 140 ms 26128 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 26140 KB Output is correct
2 Correct 34 ms 26140 KB Output is correct
3 Correct 39 ms 26140 KB Output is correct
4 Correct 31 ms 26140 KB Output is correct
5 Correct 25 ms 26140 KB Output is correct
6 Correct 29 ms 26140 KB Output is correct
7 Correct 30 ms 26140 KB Output is correct
8 Correct 30 ms 26140 KB Output is correct
9 Correct 37 ms 26140 KB Output is correct
10 Correct 27 ms 26140 KB Output is correct
11 Correct 30 ms 26140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 24408 KB 3rd lines differ - on the 26th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -