Submission #789604

# Submission time Handle Problem Language Result Execution time Memory
789604 2023-07-21T14:33:34 Z esomer Toy Train (IOI17_train) C++17
11 / 100
7 ms 1340 KB
#include<bits/stdc++.h>
#include "train.h"

using namespace std;

typedef long long ll;

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>> radj(n);
	vector<int> out(n, 0);
	for(int i = 0; i < m; 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);
			}
		}
	}
	radj.assign(n, {});
	out.assign(n, 0);
	for(int i = 0; i < m; i++){
		if(forced[U[i]] == 1) continue;
		out[U[i]]++;
		radj[V[i]].push_back(U[i]);
	}
	for(int i = 0; i < n; i++){
		if(out[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] == 0) {q.push(node); forced[node] = 1;}
			if(A[node] == 0 && forced[node] == 0){
				forced[node] = 1;
				q.push(node);
			}
		}
	}
	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 4 ms 852 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 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB 3rd lines differ - on the 4th token, expected: '0', found: '1'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1236 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 4 ms 980 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 5 ms 1208 KB Output is correct
4 Correct 6 ms 1340 KB Output is correct
5 Correct 5 ms 1204 KB Output is correct
6 Correct 5 ms 1236 KB Output is correct
7 Correct 5 ms 1236 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 5 ms 1072 KB Output is correct
10 Correct 5 ms 1236 KB Output is correct
11 Correct 5 ms 1236 KB Output is correct
12 Correct 7 ms 1204 KB Output is correct
13 Correct 6 ms 1212 KB Output is correct
14 Correct 5 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1208 KB Output is correct
2 Correct 5 ms 1216 KB Output is correct
3 Correct 5 ms 1236 KB Output is correct
4 Correct 5 ms 1108 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 4 ms 904 KB Output is correct
8 Incorrect 4 ms 852 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 4 ms 852 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -