Submission #427578

# Submission time Handle Problem Language Result Execution time Memory
427578 2021-06-14T17:24:33 Z markthitrin Toy Train (IOI17_train) C++14
23 / 100
962 ms 65024 KB
#include "train.h"
#include <vector>
#include <iostream>
int N,M;
std::vector<int> f[5005];
std::vector<int> inv_f[5005];
std::vector<int> ans;
int degree[5005];
int m[5005];
bool come[5005];
bool reachable[5005];
bool visit[5005];
void inv_bfs(std::vector<int>& a,int pos){
    if(come[pos])
        return;
    come[pos] = true;
    for(int q = 0;q<inv_f[pos].size();q++){
        m[inv_f[pos][q]]++;
        if(a[inv_f[pos][q]] == 0 && degree[inv_f[pos][q]] == m[inv_f[pos][q]]){
            inv_bfs(a,inv_f[pos][q]);
        }
        else if(a[inv_f[pos][q]] == 1)
            inv_bfs(a,inv_f[pos][q]);
    }
}
void bfs(std::vector<int>& a,int pos){
    if(visit[pos])
        return;
    visit[pos]  =true;
    for(int q = 0 ;q<f[pos].size();q++){
        if(come[f[pos][q]]){
            reachable[f[pos][q]] = true;
            bfs(a,f[pos][q]);
        }
    }
}
void last_func(std::vector<int> a,int pos){
    if(visit[pos])
        return;
    visit[pos] = true;
    ans[pos] = 1;
    for(int q = 0 ;q<inv_f[pos].size();q++){
        m[inv_f[pos][q]]++;
        if(a[inv_f[pos][q]] == 0 && degree[inv_f[pos][q]] == m[inv_f[pos][q]]){
            last_func(a,inv_f[pos][q]);
        }
        else if(a[inv_f[pos][q]] == 1)
            last_func(a,inv_f[pos][q]);
    }
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	N = a.size();
	M = u.size();
    for(int q = 0 ;q<N;q++){
        ans.push_back(0);
    }
	for(int q = 0 ;q<M;q++){
        f[u[q]].push_back(v[q]);
        inv_f[v[q]].push_back(u[q]);
        degree[u[q]]++;
	}
	for(int q = 0;q<N;q++){
        if(r[q]){
            for(int w = 0 ;w<N;w++){
                m[w] = 0;
                come[w] = false;
                visit[w] = false;
            }
            inv_bfs(a,q);
            bfs(a,q);
        }
	}
    for(int w = 0;w<N;w++){
        m[w] = 0;
    }
    for(int w = 0 ;w<N;w++){
        visit[w] = false;
    }
	for(int q= 0;q<N;q++){
        if(reachable[q])
            last_func(a,q);
	}
	return ans;
}
/*
2 4
0 1
1 0
0 0
0 1
1 0
1 1
1 1
*/

Compilation message

train.cpp: In function 'void inv_bfs(std::vector<int>&, int)':
train.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int q = 0;q<inv_f[pos].size();q++){
      |                   ~^~~~~~~~~~~~~~~~~~
train.cpp: In function 'void bfs(std::vector<int>&, int)':
train.cpp:30:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int q = 0 ;q<f[pos].size();q++){
      |                    ~^~~~~~~~~~~~~~
train.cpp: In function 'void last_func(std::vector<int>, int)':
train.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int q = 0 ;q<inv_f[pos].size();q++){
      |                    ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1608 KB 3rd lines differ - on the 42nd 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 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 105 ms 1764 KB Output is correct
2 Correct 178 ms 1776 KB Output is correct
3 Correct 233 ms 1860 KB Output is correct
4 Correct 962 ms 57844 KB Output is correct
5 Correct 178 ms 41036 KB Output is correct
6 Correct 20 ms 2856 KB Output is correct
7 Correct 482 ms 3912 KB Output is correct
8 Correct 36 ms 8304 KB Output is correct
9 Correct 8 ms 1612 KB Output is correct
10 Correct 58 ms 6420 KB Output is correct
11 Correct 37 ms 4268 KB Output is correct
12 Correct 10 ms 1472 KB Output is correct
13 Correct 85 ms 63816 KB Output is correct
14 Correct 79 ms 61696 KB Output is correct
15 Correct 78 ms 65024 KB Output is correct
16 Correct 77 ms 62444 KB Output is correct
17 Correct 80 ms 62744 KB Output is correct
18 Correct 299 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 1228 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 18 ms 1852 KB Output is correct
2 Correct 69 ms 47120 KB Output is correct
3 Correct 38 ms 14632 KB Output is correct
4 Correct 43 ms 20640 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 5 ms 972 KB Output is correct
7 Correct 7 ms 1572 KB Output is correct
8 Correct 6 ms 1068 KB Output is correct
9 Correct 7 ms 1612 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 8 ms 2204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1608 KB 3rd lines differ - on the 42nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -