Submission #70853

# Submission time Handle Problem Language Result Execution time Memory
70853 2018-08-23T14:16:48 Z Kmcode Toy Train (IOI17_train) C++14
11 / 100
1495 ms 4752 KB
#include <bits/stdc++.h>
 
using namespace std;
 
 
//#include "train.h"
 
vector<int> v[5002];
vector<int> rv[5002];
bool use[5002];
 
int sz[5002];
 
vector<int> bc;
inline void dfs(int b){
	use[b]=true;
	for(int go:v[b]){
		if(use[go]==false){
			dfs(go);
		}
	}
	bc.push_back(b);
}
int belong[5002];
inline void dfs2(int b,int be){
	use[b]=false;
	belong[b]=be;
  	sz[be]++;
	for(int go:rv[b]){
		if(use[go]){
			dfs2(go,be);
		}
	}
}
 
int m;
int n;
 
void scc(){
	for(int i=0;i<n;i++){
		if(use[i]==false){
			dfs(i);
		}
	}
	reverse(bc.begin(),bc.end());
	for(int i=0;i<bc.size();i++){
		if(use[bc[i]]){
			dfs2(bc[i],m);
			m++;
		}
	}
}
vector<int> ed[5002];
bool ok[5002];
 
int us[5002];
int u_s;
 
bool bor[5002];
bool are[5002];
vector<int> r;
 
 
 
inline bool a_walk(int node){
	us[node]=u_s;
	if(are[node])return true;
	if(ok[belong[node]]==false&&sz[belong[node]]>1)return true;
	for(int go:v[node]){
		if(us[go]!=u_s){
			if(a_walk(go))return true;
		}
	}
	return false;
}
inline bool b_walk(int node){
	us[node]=u_s;
	if(bor[node])return true;
	if(sz[belong[node]]>1)return true;
	for(int go:v[node]){
		if(us[go]!=u_s){
			if(b_walk(go))return true;
		}
	}
	return false;
} 
std::vector<int> who_wins(std::vector<int> a1, std::vector<int> r1, std::vector<int> u1, std::vector<int> v1) {
	r=r1;
	n=a1.size();
	for(int i=0;i<u1.size();i++){
		if(u1[i]==v1[i]){
			if(r1[u1[i]]){
				are[u1[i]]=true;
			}
			else{
				bor[u1[i]]=true;
			}
			continue;
		}
      		if(r[u1[i]]||r[v1[i]])continue;
		v[u1[i]].push_back(v1[i]);
		rv[v1[i]].push_back(u1[i]);
	}
	scc();
	for(int i=0;i<n;i++){
		ok[belong[i]]|=r1[i];
	}
	vector<int> ret(a1.size(),1);
  	for(int i=0;i<n;i++)v[i].clear();
  	for(int i=0;i<u1.size();i++)v[u1[i]].push_back(v1[i]);
	for(int i=0;i<n;i++){
		u_s++;
		if(b_walk(i)){
			ret[i]=0;
		}
	}
	return ret;
}

Compilation message

train.cpp: In function 'void scc()':
train.cpp:46:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<bc.size();i++){
              ~^~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:90:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<u1.size();i++){
              ~^~~~~~~~~~
train.cpp:110:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0;i<u1.size();i++)v[u1[i]].push_back(v1[i]);
                ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1112 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 2 ms 1112 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 145 ms 1820 KB Output is correct
2 Correct 43 ms 1912 KB Output is correct
3 Correct 17 ms 1912 KB Output is correct
4 Incorrect 15 ms 1912 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 Correct 1225 ms 1912 KB Output is correct
2 Correct 94 ms 2048 KB Output is correct
3 Correct 21 ms 2388 KB Output is correct
4 Correct 16 ms 2460 KB Output is correct
5 Correct 248 ms 2840 KB Output is correct
6 Correct 455 ms 3040 KB Output is correct
7 Correct 402 ms 3260 KB Output is correct
8 Correct 17 ms 3260 KB Output is correct
9 Correct 29 ms 3272 KB Output is correct
10 Correct 1495 ms 3712 KB Output is correct
11 Correct 1420 ms 3920 KB Output is correct
12 Correct 1447 ms 4128 KB Output is correct
13 Correct 27 ms 4480 KB Output is correct
14 Correct 41 ms 4576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 4752 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 9 ms 1112 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -