Submission #1037590

# Submission time Handle Problem Language Result Execution time Memory
1037590 2024-07-29T05:23:23 Z 12345678 Toy Train (IOI17_train) C++17
0 / 100
12 ms 1532 KB
#include "train.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=5e3+5;

int n, cy[nx], pa[nx], vs[nx], f;
vector<int> d[nx], rv[nx];

void dfs(int u, int rt)
{
    vs[u]=1;
    if (f) return;
    for (auto v:d[u])
    {
        if (!f&&v==rt)
        {
            int tmp=u;
            while (tmp!=rt) cy[tmp]=1, tmp=pa[tmp];
            cy[rt]=1;
            f=1;
            return;
        }
        if (vs[v]) continue;
        pa[v]=u;
        dfs(v, rt);
    }
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
    n=a.size();
    for (int i=0; i<u.size(); i++) d[u[i]].push_back(v[i]), rv[v[i]].push_back(u[i]);
    for (int i=0; i<n; i++) 
    {
        if (r[i]) 
        {
            for (int j=0; j<n;j ++) vs[j]=1;
            dfs(i, i);    
        }
    }
    vector<int> res(n);
    queue<int> q;
    for (int i=0; i<n;i ++) vs[i]=0;
    for (int i=0; i<n;i ++) if (cy[i]) q.push(i), vs[i]=1;
    while (!q.empty())
    {
        auto cur=q.front();
        q.pop();
        res[cur]=1;
        for (auto x:rv[cur]) if (!vs[x]) vs[x]=1,q.push(x);
    }
    return res;
}

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:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i=0; i<u.size(); i++) d[u[i]].push_back(v[i]), rv[v[i]].push_back(u[i]);
      |                   ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1116 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 600 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 5 ms 1372 KB Output is correct
2 Correct 6 ms 1372 KB Output is correct
3 Correct 6 ms 1372 KB Output is correct
4 Incorrect 7 ms 1532 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 1368 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 Incorrect 5 ms 1372 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 Incorrect 6 ms 1116 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -