Submission #413036

# Submission time Handle Problem Language Result Execution time Memory
413036 2021-05-28T06:35:12 Z 조영욱(#7624) Toy Train (IOI17_train) C++14
0 / 100
2000 ms 1680 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> adj[5000];
vector<int> gph[5000];
bool vis[5000];
int deg[5000];

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
    int n=a.size();
    int m=u.size();
    for(int i=0;i<m;i++) {
        gph[u[i]].push_back(v[i]);
    }
    vector<int> ret(n);
    for(int st=0;st<n;st++) {
        queue<int> q;
        q.push(st);
        memset(vis,0,sizeof(vis));
        vis[st]=true;
        while (!q.empty()) {
            int now=q.front();
            q.pop();
            for(int i=0;i<gph[now].size();i++) {
                int nt=gph[now][i];
                if (vis[nt]) {
                    continue;
                }
                vis[nt]=true;
                q.push(nt);
            }
        }
        for(int i=0;i<n;i++) {
            adj[i].clear();
        }
        memset(deg,0,sizeof(deg));
        for(int i=0;i<m;i++) {
            if (r[u[i]]==0&&r[v[i]]==0&&vis[u[i]]&&vis[v[i]]) {
                adj[u[i]].push_back(v[i]);
                deg[v[i]]++;
            }
        }
        for(int i=0;i<n;i++) {
            if (deg[i]==0) {
                q.push(i);
            }
        }
        int cnt=0;
        while (!q.empty()) {
            int now=q.front();
            q.pop();
            cnt++;
            for(int i=0;i<adj[now].size();i++) {
                int nt=adj[now][i];
                deg[nt]--;
                if (deg[nt]==0) {
                    q.push(nt);
                }
            }
        }
        ret[st]=(cnt==n);
    }
    return ret;
}

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:25:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |             for(int i=0;i<gph[now].size();i++) {
      |                         ~^~~~~~~~~~~~~~~~
train.cpp:54:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             for(int i=0;i<adj[now].size();i++) {
      |                         ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 957 ms 1092 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 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 1033 ms 1680 KB Output is correct
2 Correct 941 ms 1548 KB Output is correct
3 Correct 917 ms 1504 KB Output is correct
4 Execution timed out 2074 ms 1396 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1292 ms 1184 KB Output is correct
2 Correct 1347 ms 1680 KB Output is correct
3 Execution timed out 2066 ms 1576 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2069 ms 1484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 957 ms 1092 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -