Submission #789584

# Submission time Handle Problem Language Result Execution time Memory
789584 2023-07-21T14:20:17 Z esomer Toy Train (IOI17_train) C++17
0 / 100
7 ms 1880 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, vector<int>& A){
	if(forced[x] == 1) return 1;
	else if(vis[x] == 1) return 0;
	vis[x] = 1;
	int mn = 1;
	int mx = 0;
	for(int node : adj[x]){
		if(A[x] == 1) mn = min(mn, DFS(node, adj, vis, forced, A));
		else mx = max(mx, DFS(node, adj, vis, forced, A));
	}
	if(A[x] == 1){
		if(mn == 1) forced[x] = 1;
		else forced[x] = 0;	
		return mn;
	}else{
		if(mx == 1) forced[x] = 1;
		else forced[x] = 0;	
		return mx;
	}
}

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) 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){
			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);
			}
		}
	}
	vector<bool> vis(n, 0);
	for(int i = 0; i < n; i++){
		if(!vis[i]){
			DFS(i, adj, vis, forced, A);
		}
	}
	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 984 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 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 3rd lines differ - on the 6th token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1876 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 Correct 7 ms 1460 KB Output is correct
2 Incorrect 6 ms 1476 KB 3rd lines differ - on the 458th token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1620 KB Output is correct
2 Correct 7 ms 1880 KB Output is correct
3 Correct 7 ms 1724 KB Output is correct
4 Correct 6 ms 1672 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 1104 KB Output is correct
7 Correct 5 ms 980 KB Output is correct
8 Incorrect 4 ms 1080 KB 3rd lines differ - on the 5th token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 984 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -