Submission #789572

# Submission time Handle Problem Language Result Execution time Memory
789572 2023-07-21T14:01:41 Z esomer Toy Train (IOI17_train) C++17
0 / 100
8 ms 1620 KB
#include<bits/stdc++.h>
#include "train.h"

using namespace std;

typedef long long ll;

int DFS(int x, vector<vector<int>>& adj, vector<bool>& vis, vector<bool>& forced){
	if(forced[x] == 1) return 1;
	else if(vis[x] == 1) return 0;
	vis[x] = 1;
	int mn = 1;
	for(int node : adj[x]){
		mn = min(mn, DFS(node, adj, vis, forced));
	}
	if(mn == 1) forced[x] = 1;
	else forced[x] = 0;
	return mn;
}

vector<int> who_wins(vector<int> A, vector<int> R, vector<int> U, vector<int> V){
	int n = (int)A.size();
	int m = (int)U.size();
	vector<vector<int>> adj(n);
	vector<vector<int>> radj(n);
	vector<int> out(n, 0);
	for(int i = 0; i < m; i++){
		adj[U[i]].push_back(V[i]);
		if(R[U[i]] == 1 || R[V[i]] == 1) continue;
		out[U[i]]++;
		radj[V[i]].push_back(U[i]);
	}
	vector<bool> forced(n, 1); //If 1, then it can be forced by B into a cycle with no R's.
	queue<int> q;
	for(int i = 0; i < n; i++){
		if(out[i] == 0 && R[i] == 0){
			forced[i] = 0;
			q.push(i);
		}
	}
	while(!q.empty()){
		int x = q.front(); q.pop();
		for(int node : radj[x]){
			out[node]--;
			if(out[node] == 0 && forced[node] == 1) {q.push(node); forced[node] = 0;}
			if(A[node] == 1 && forced[node] == 1){
				forced[node] = 0;
				q.push(node);
			}
		}
	}
	for(int i = 0; i < n; i++){
		bool has = 0;
		for(int node : adj[i]){
			if(R[node] == 1) has = 1;
		}
		if(R[i] == 1 || (has == 1 && A[i] == 1)) forced[i] = 0;
	}
	vector<bool> vis(n, 0);
	for(int i = 0; i < n; i++){
		if(!vis[i]){
			DFS(i, adj, vis, forced);
		}
	}
	vector<int> ans(n);
	for(int i = 0; i < n; i++){
		if(forced[i] == 1) ans[i] = 0;
		else ans[i] = 1;
	}
	return ans;
}

//~ int main() {
	
	//~ freopen("in.txt", "r", stdin);
	
	//~ int n, m;
	//~ assert(2 == scanf("%d %d", &n, &m));

	//~ vector<int> a(n), r(n), u(m), v(m);

	//~ for(int i = 0; i < n; i++)
		//~ assert(1 == scanf("%d", &a[i]));

	//~ for(int i = 0; i < n; i++)
		//~ assert(1 == scanf("%d", &r[i]));

	//~ for(int i = 0; i < m; i++)
		//~ assert(2 == scanf("%d %d", &u[i], &v[i]));

	//~ vector<int> res = who_wins(a, r, u, v);

	//~ for(int i = 0; i < (int)res.size(); i++)
		//~ printf(i ? " %d" : "%d", res[i]);
	//~ printf("\n");

	//~ return 0;
//~ }
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 980 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 0 ms 212 KB 3rd lines differ - on the 8th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1620 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 4 ms 1364 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 Correct 7 ms 1592 KB Output is correct
2 Incorrect 8 ms 1492 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 980 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -