답안 #798054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798054 2023-07-30T10:24:31 Z LittleCube 장난감 기차 (IOI17_train) C++17
11 / 100
7 ms 1876 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

int n, m, k, vis[5005], scc[5005], self[5005];
vector<int> E[5005], R[5005];
vector<int> order;
vector<int> cc[5005];

void dfs(int u)
{
	vis[u] = 1;
	for (auto v : E[u])
		if (!vis[v])
			dfs(v);
	order.emplace_back(u);
}

void dfscc(int u, int c)
{
	vis[u] = 1;
	scc[u] = c;
	cc[c].emplace_back(u);
	for (auto v : R[u])
		if (!vis[v])
			dfscc(v, c);
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v)
{
	n = a.size(), m = u.size(), k = -1;
	for (int i = 0; i < n + 1; i++)
		vis[i] = 0, E[i].clear(), R[i].clear(), cc[i].clear(), self[i] = 0;

	// Check solely A
	order.clear();
	for (int i = 0; i < m; i++)
	{
		if (a[u[i]] == 1 && a[v[i]] == 1)
		{
			E[u[i]].emplace_back(v[i]);
			R[v[i]].emplace_back(u[i]);
		}
		if (u[i] == v[i])
			self[u[i]] = 1;
	}

	for (int i = 0; i < n; i++)
		if (!vis[i] && a[i] == 1)
			dfs(i);
	reverse(order.begin(), order.end());
	for (int i = 0; i < n; i++)
		vis[i] = 0;
	for (int i : order)
		if (!vis[i] && a[i] == 1)
			dfscc(i, ++k);

	vector<int> ans(n, 0);

	for (int i = k; i >= 0; i--)
	{
		int flag = 0;
		for (int j : cc[i])
		{
			for (int p : E[j])
				if (ans[p])
					flag = 1;
			if (r[j] == 1 && (cc[i].size() > 1 || self[j]))
				flag = 1;
		}
		if (flag)
			for (int j : cc[i])
				ans[j] = 1;
	}

	// Check B (no charging stations)
	for (int i = 0; i < n + 1; i++)
		vis[i] = 0, E[i].clear(), R[i].clear(), cc[i].clear(), self[i] = 0;
	order.clear();
	for (int i = 0; i < m; i++)
	{
		if (a[u[i]] == 0 && a[v[i]] == 0 && !r[u[i]] && !r[v[i]])
		{
			E[u[i]].emplace_back(v[i]);
			R[v[i]].emplace_back(u[i]);
			if (u[i] == v[i])
				self[u[i]] = 1;
		}
	}

	for (int i = 0; i < n; i++)
		if (!vis[i] && a[i] == 0 && !r[i])
			dfs(i);
	reverse(order.begin(), order.end());
	for (int i = 0; i < n; i++)
		vis[i] = 0;
	for (int i : order)
		if (!vis[i] && a[i] == 0 && !r[i])
			dfscc(i, ++k);

	for (int i = k; i >= 0; i--)
	{
		int flag = 0;
		for (int j : cc[i])
		{
			for (int p : E[j])
				if (ans[p])
					flag = 1;
			if (r[j] == 1 && (cc[i].size() > 1 || self[j]))
				flag = 1;
		}
		if (!flag)
			for (int j : cc[i])
				ans[j] = 1;
	}

	// check mixed
	for (int i = 0; i < n + 1; i++)
		E[i].clear(), R[i].clear();
	for (int i = 0; i < m; i++)
	{
		E[u[i]].emplace_back(v[i]);
		R[v[i]].emplace_back(u[i]);
	}

	vector<int> req(n, 0);
	queue<int> q;

	for (int j = 0; j < n; j++)
		if (ans[j])
		{
			q.push(j);
			req[j] = 0;
		}
		else if (a[j])
			req[j] = 1;
		else
			req[j] = E[j].size();

	while (!q.empty())
	{
		int x = q.front();
		q.pop();
		for (auto y : R[x])
			if (--req[y] == 0)
			{
				q.emplace(y);
				ans[y] = 1;
			}
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1364 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1876 KB Output is correct
2 Correct 5 ms 1748 KB Output is correct
3 Correct 5 ms 1748 KB Output is correct
4 Correct 7 ms 1796 KB Output is correct
5 Correct 6 ms 1748 KB Output is correct
6 Correct 6 ms 1596 KB Output is correct
7 Correct 7 ms 1620 KB Output is correct
8 Correct 6 ms 1620 KB Output is correct
9 Correct 6 ms 1620 KB Output is correct
10 Correct 6 ms 1608 KB Output is correct
11 Correct 7 ms 1588 KB Output is correct
12 Correct 6 ms 1620 KB Output is correct
13 Correct 7 ms 1748 KB Output is correct
14 Correct 7 ms 1812 KB Output is correct
15 Correct 6 ms 1760 KB Output is correct
16 Correct 6 ms 1748 KB Output is correct
17 Correct 7 ms 1752 KB Output is correct
18 Correct 4 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1364 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1628 KB 3rd lines differ - on the 9th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1364 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -