Submission #798031

# Submission time Handle Problem Language Result Execution time Memory
798031 2023-07-30T09:50:55 Z LittleCube Toy Train (IOI17_train) C++17
0 / 100
5 ms 1876 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

int n, m, k, vis[5005], scc[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 = 0;
	for (int i = 0; i < n + 1; i++)
		vis[i] = 0, E[i].clear(), R[i].clear(), cc[i].clear();
	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]);
		}

	for (int i = 0; i < n; i++)
		if (!vis[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])
			dfscc(i, k++);

	vector<int> ans(n, 0);

	for (int i = k - 1; 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)
				flag = 1;
		}
		if(flag)
			for (int j : cc[i])
				ans[j] = 1;
	}
	return ans;
	// vector<int>
	// 	loop(n, 0);
	// for (int i = 0; i < n; i++)
	// 	if (a[i] == 0)
	// 	{
	// 		vector<int> req(n, 0);
	// 		for (int j = 0; j < n; j++)
	// 			if (r[j])
	// 				req[j] = 1e9;
	// 			else if (a[j])
	// 				req[j] = E[j].size();
	// 			else
	// 				req[j] = 1;
	// 		queue<int> q;
	// 		q.push(i);
	// 		while (!q.empty())
	// 		{
	// 			int x = q.front();
	// 			q.pop();
	// 			for (auto y : R[x])
	// 				if (--req[y] == 0)
	// 					q.emplace(y);
	// 		}
	// 		loop[i] = req[i] <= 0;
	// 	}
	// vector<int> ans(n, 1);
	// vector<int> req(n, 0);
	// queue<int> q;

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

	// while (!q.empty())
	// {
	// 	int x = q.front();
	// 	ans[x] = 0;
	// 	q.pop();
	// 	for (auto y : R[x])
	// 		if (--req[y] == 0)
	// 			q.emplace(y);
	// }
	// return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1108 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 Incorrect 0 ms 596 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 Incorrect 5 ms 1876 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 Incorrect 4 ms 1196 KB 3rd lines differ - on the 21st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1236 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 1108 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -