Submission #704014

#TimeUsernameProblemLanguageResultExecution timeMemory
704014Abrar_Al_SamitToy Train (IOI17_train)C++17
27 / 100
2052 ms1864 KiB
#include<bits/stdc++.h>
#include "train.h"
using namespace std;

const int nax = 5000;
int n, m;
vector<int>g[nax], gt[nax];
vector<int>A, R;

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=0; i<m; ++i) {
		g[u[i]].push_back(v[i]);
		gt[v[i]].push_back(u[i]);
	}

	A = a, R = r;
	vector<int>res(n);

	while(1) {
		set<int>nontrap, trap;
		for(int i=0; i<n; ++i) {
			if(R[i]) nontrap.insert(i);
			else trap.insert(i);
		}


		vector<int>trans;

		while(1) {
			for(int x : trap) {
				bool all = true, one = false;
				for(int to : g[x]) {
					all &= nontrap.count(to);
					one |= nontrap.count(to);
				}
				if(A[x] && one) {
					trans.push_back(x);
				} else if(!A[x] && all) {
					trans.push_back(x);
				}
			}
			if(trans.empty()) break;
			for(int x : trans) {
				trap.erase(x);
				nontrap.insert(x);
			}
			trans.clear();
		}

		for(int x : nontrap) {
			bool all = true, one = false;
			for(int to : g[x]) {
				all &= trap.count(to);
				one |= trap.count(to);
			}

			if(A[x] && all) {
				trans.push_back(x);
			} else if(!A[x] && one) {
				trans.push_back(x);
			}
		}
		if(trans.empty()) {
			for(int x : nontrap) res[x] = 1;
			break;
		}
		for(int x : trans) {
			trap.insert(x);
			nontrap.erase(x);
			R[x] = 0;
		}
	}
	return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...