Submission #413040

# Submission time Handle Problem Language Result Execution time Memory
413040 2021-05-28T06:50:07 Z 조영욱(#7624) Toy Train (IOI17_train) C++14
0 / 100
1291 ms 1652 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];
bool chk[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 i=0;i<n;i++) {
        ret[i]=1;
    }
    for(int st=0;st<n;st++) {
        if (chk[st]) {
            continue;
        }
        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);
                }
            }
        }
        for(int i=0;i<n;i++) {
            if (deg[i]!=0) {
                chk[i]=true;
                ret[i]=0;
            }
        }
    }
    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:32:26: 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<gph[now].size();i++) {
      |                         ~^~~~~~~~~~~~~~~~
train.cpp:61:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             for(int i=0;i<adj[now].size();i++) {
      |                         ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 733 ms 1256 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 1 ms 460 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 920 ms 1652 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 1291 ms 1228 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 114 ms 1484 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 733 ms 1256 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -