Submission #768074

# Submission time Handle Problem Language Result Execution time Memory
768074 2023-06-27T12:20:37 Z SanguineChameleon Toy Train (IOI17_train) C++17
0 / 100
108 ms 1260 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e3 + 20;
int deg[maxn];
vector<int> adj[maxn];
int cnt[maxn];
int owner[maxn];
bool rem[maxn];
bool flag[maxn][2];
int n;

void bfs(int player) {
	deque<int> q;
	for (int i = 0; i < n; i++) {
		if (!rem[i] && flag[i][player]) {
			q.push_back(i);
		}
		cnt[i] = 0;
	}
	while (!q.empty()) {
		int u = q.front();
		q.pop_front();
		for (auto v: adj[u]) {
			if (flag[v][player]) {
				continue;
			}
			cnt[v]++;
			if (owner[v] == player) {
				if (cnt[v] == 1) {
					flag[v][player] = true;
					q.push_back(v);
				}
			}
			else {
				if (cnt[v] == deg[v]) {
					flag[v][player] = true;
					q.push_back(v);
				}
			}
		}
	}
	cout << '\n';
}

vector<int> who_wins(vector<int> _owner, vector<int> charge, vector<int> u, vector<int> v) {
	n = _owner.size();
	for (int i = 0; i < n; i++) {
		owner[i] = _owner[i];
	}
	int m = u.size();
	vector<int> res(n);
	while (true) {
		for (int i = 0; i < n; i++) {
			deg[i] = 0;
			adj[i].clear();
			flag[i][0] = false;
			flag[i][1] = false;
		}
		for (int i = 0; i < m; i++) {
			if (!rem[u[i]] && !rem[v[i]]) {
				deg[u[i]]++;
				adj[v[i]].push_back(u[i]);
			}
		}
		for (int i = 0; i < n; i++) {
			if (!rem[i] && charge[i]) {
				flag[i][1] = true;
			}
		}
		bfs(1);
		bool done = true;
		for (int i = 0; i < n; i++) {
			if (!rem[i] && !flag[i][1]) {
				flag[i][0] = true;
				done = false;
			}
		}
		if (done) {
			for (int i = 0; i < n; i++) {
				if (!rem[i]) {
					res[i] = 1;
				}
			}
			break;
		}
		bfs(0);
		for (int i = 0; i < n; i++) {
			if (!rem[i] && flag[i][0]) {
				res[i] = 0;
				rem[i] = true;
			}
		}
	}
	return res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 860 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 432 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 1260 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1108 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1236 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 860 KB secret mismatch
2 Halted 0 ms 0 KB -