Submission #282488

# Submission time Handle Problem Language Result Execution time Memory
282488 2020-08-24T13:06:29 Z MohamedAhmed04 Toy Train (IOI17_train) C++14
0 / 100
13 ms 2560 KB
#include <bits/stdc++.h>
#include "train.h"
//#include "grader.cpp"
 
using namespace std ;
 
const int MAX = 5010 ;
 
int A[MAX] , R[MAX] , vis[MAX] , vis2[MAX] ;

vector< vector<int> >adj(MAX) ;
vector< vector<int> >adj2(MAX) ;
vector< vector<int> >sccadj(MAX) ;
int n , m ;

vector<int>topo ;
int comb[MAX] ;
vector<int>combnodes[MAX] ;
int dp[MAX] ;

void dfs(int node)
{
	vis[node] = 1 ;
	for(auto &child : adj[node])
	{
		if(vis[child])
			continue ;
		dfs(child) ;
	}
	topo.push_back(node) ;
}

int id = 0 ;

void dfs2(int node)
{
	vis2[node] = 1 ;
	comb[node] = id ;
	combnodes[id].push_back(node) ;
	for(auto &child : adj2[node])
	{
		if(vis2[child])
			continue ;
		dfs2(child) ;
	}
}

void dfs3(int node)
{
	vis[node] = 1 ; 
	for(auto &child : sccadj[node])
	{
		if(vis[child])
			continue ;
		dfs3(child) ;
	}
	topo.push_back(node) ;
}


vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) 
{
	n = a.size() ;
	m = u.size() ;
	for(int i = 1 ; i <= n ; ++i)
		A[i] = a[i-1] , R[i] = r[i-1] ;
	for(int i = 0 ; i < m ; ++i)
	{
		adj[u[i]+1].push_back(v[i]+1) ;
		adj2[v[i]+1].push_back(u[i]+1) ;
	}
	for(int i = 1 ; i <= n ; ++i)
	{
		if(vis[i])
			continue ;
		dfs(i) ;
	}
	reverse(topo.begin() , topo.end()) ;
	for(auto &i : topo)
	{
		if(vis2[i])
			continue ;
		++id ;
		dfs2(i) ;
	}
	for(int i = 1 ; i <= id ; ++i)
	{
		for(auto &node : combnodes[i])
		{
			for(auto &child : adj[node])
			{
				if(comb[child] != i)
					sccadj[i].push_back(comb[child]) ;
			}
		}
	}
	topo.clear() ;
	memset(vis , 0 , sizeof(vis)) ;
	for(int i = 1 ; i <= id ; ++i)
	{
		if(vis[i])
			continue ;
		dfs3(i) ;
	}
	reverse(topo.begin() , topo.end()) ;
	for(int i = topo.size()-1 ; i >= 0 ; --i)
	{
		int id = topo[i] ;
		dp[id] = 0 ;
		for(auto &node : combnodes[id])
			dp[id] |= R[node] ;
		for(auto &child : sccadj[id])
			dp[id] |= dp[child] ; 
	}
	vector<int>ans ;
	for(int i = 1 ; i <= n ; ++i)
	{
		if(dp[comb[i]])
			ans.push_back(1) ;
		else
			ans.push_back(0) ;
	}
	return ans ;
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2048 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 768 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 12 ms 2560 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 9 ms 1920 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 13 ms 2176 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2048 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -