Submission #428706

# Submission time Handle Problem Language Result Execution time Memory
428706 2021-06-15T14:00:34 Z REALITYNB Toy Train (IOI17_train) C++14
0 / 100
2000 ms 197268 KB
#include <bits/stdc++.h>
#include "train.h"
using namespace std;
const int N = 5001 ;
vector<int> adj[N] ;
void dfs(int i , vector<int>&vis,bool flg , vector<int>& r ){
    vis[i]=1 ;
    for(int x: adj[i]){
        if(flg){
            if(vis[x]==0&&r[x]==0){
                dfs(x,vis,flg,r);
            }
            continue ;
        }
        if(vis[x]==0) dfs(x,vis,flg,r) ;
    }
    return ;
}
vector<int> who_wins(vector<int> a,vector<int> r,vector<int> u,vector<int>v){
    int n = a.size() ;
    for(int i=0;i<u.size();i++)adj[u[i]].push_back(v[i]) ;
    vector<vector<int>> reachable(n) ;
    for(int i=0;i<n;i++){
        reachable[i].resize(n) ;
        dfs(i,reachable[i],0,r);
                reachable[i][i]=0 ;
        for(int x : adj[i]) if(x==i) reachable[i][i]=1;
    }
    vector<int> cycle(n) ;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(reachable[i][j]&&reachable[j][i]){
                cycle[i]=1;
            }
        }
    }
    vector<vector<int>> reachablee(n) ;
    for(int i=0;i<n;i++){
        reachablee[i].resize(n);
        if(r[i]) continue ;
        dfs(i,reachablee[i],1,r) ;
        reachablee[i][i]=0;
        for(int x: adj[i]) if(x==i) reachablee[i][i]=1 ;
    }
    vector<int> cyclee(n) ;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(reachablee[i][j]&&reachablee[j][i]){
                cyclee[j]=1;
            }
        }
    }
    bool flg = 0;
    for(int i=0;i<n;i++) if(adj[i].empty()) flg=1;
    vector<int> ans(n) ;
    for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(adj[j].empty()&&(reachable[i][j]||i==j)){
                    ans[i]=1;
                    break;
                }
                if(cyclee[j]&&(reachable[i][j]||i==j)){
                    ans[i]=1 ;
                    break ;
                }
            }

    }
    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:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i=0;i<u.size();i++)adj[u[i]].push_back(v[i]) ;
      |                 ~^~~~~~~~~
train.cpp:53:10: warning: variable 'flg' set but not used [-Wunused-but-set-variable]
   53 |     bool flg = 0;
      |          ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 520 ms 197060 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 332 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 691 ms 197268 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 1200 ms 197068 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 Execution timed out 2101 ms 166936 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 520 ms 197060 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -