Submission #789651

# Submission time Handle Problem Language Result Execution time Memory
789651 2023-07-21T16:04:02 Z esomer Toy Train (IOI17_train) C++17
0 / 100
7 ms 1296 KB
#include<bits/stdc++.h>
#include "train.h"
 
using namespace std;
 
typedef long long ll;
 
void process(vector<int>& A, vector<int>& R, vector<int>& U, vector<int>& V, vector<bool>& forced, vector<int>& out, vector<vector<int>>& radj){
	int n = (int)A.size();
	int m = (int)U.size();
	queue<int> q;
	for(int i = 0; i < n; i++){
		if(out[i] == 0){
			forced[i] = 0;
			q.push(i);
		}
	}
	vector<int> org = out;
	while(!q.empty()){
		int x = q.front(); q.pop();
		for(int node : radj[x]){
			out[node]--;
			if(forced[node] == 0) continue;
			if(out[node] == 0) {q.push(node); forced[node] = 0;}
			if(A[node] == 1){
				forced[node] = 0;
				q.push(node);
			}
		}
	}
	out = org;
	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(forced[node] == 1) continue;
			if(out[node] == 0) {q.push(node); forced[node] = 1;}
			if(A[node] == 0){
				forced[node] = 1;
				q.push(node);
			}
		}
	}
	out = org;
}
 
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();
	bool stop = 0;
	vector<bool> forced; //If 1, then it can be forced by B into a cycle with no R's.
	vector<int> out(n);
	vector<vector<int>> radj(n);
	for(int i = 0; i < m; i++){
		out[U[i]]++;
		radj[V[i]].push_back(U[i]);
	}
	while(!stop){
		stop = 1;
		forced.assign(n, 1);
		process(A, R, U, V, forced, out, radj);
		for(int i = 0; i < n; i++){
			if(forced[i] == 1 && R[i] == 1) {R[i] = 0; stop = 0;}
		}
	}
	vector<int> ans(n);
	for(int i = 0; i < n; i++){
		if(forced[i] == 1) ans[i] = 0;
		else ans[i] = 1;
	}
	return ans;
}

Compilation message

train.cpp: In function 'void process(std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<bool>&, std::vector<int>&, std::vector<std::vector<int> >&)':
train.cpp:10:6: warning: unused variable 'm' [-Wunused-variable]
   10 |  int m = (int)U.size();
      |      ^
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 852 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 1 ms 212 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 7 ms 1296 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 5 ms 1248 KB Output is correct
4 Incorrect 6 ms 1204 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 Incorrect 4 ms 992 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 7 ms 1240 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 3 ms 852 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -