Submission #406836

# Submission time Handle Problem Language Result Execution time Memory
406836 2021-05-18T05:56:05 Z 8e7 Toy Train (IOI17_train) C++14
0 / 100
214 ms 2004 KB
#include "train.h"

//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define ll long long
#define maxn 5005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
vector<int> adj[maxn], rev[maxn], scc[maxn];
bool found[maxn], poss[maxn], tag[maxn]; 
int group[maxn];
int ord[maxn];
int ti = 0;
void dfs(int n) {
	found[n] = 1;
	for (int v:adj[n]) {
		if (!found[v]) {
			dfs(v);
		}
	}

	ord[ti++] = n;
}
vector<int> node;
void dfs2(int n) {
	node.push_back(n);
	found[n] = 1;
	for (int v:rev[n]) {
		if (!found[v]) dfs2(v);
	}
}
bool dfs3(int n) {
	found[n] = 1;
	if (tag[n]) return true;
	bool ret = false;
	for (int v:scc[n]) {
		if (!found[v]) ret |= dfs3(v);
	}
	return ret;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	int n = a.size(), m = u.size();
	for (int i = 0;i < m;i++) {
		adj[u[i]].push_back(v[i]);
		rev[v[i]].push_back(u[i]);
	}
	for (int i = 0;i < n;i++) {
		if (!found[i]) dfs(i);
	}
	for (int i = 0;i < n;i++) found[i] = 0;
	int cnt = 0;
	for (int i = n - 1;i >= 0;i--) {
		if (!found[ord[i]]) {
			node.clear();
			dfs2(ord[i]);
			int ans = 0;
			for (int j:node) ans |= r[j];
			if(node.size() > 1)	tag[cnt] = ans;
			for (int j:node) group[j] = cnt;
			cnt++;
		}
	}	
	for (int i = 0;i < m;i++) {
		scc[group[u[i]]].push_back(group[v[i]]);
	}
	vector<int> ret;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) found[j] = 0;
		bool res = 0;
		for (int j:scc[group[i]]) {
			if (!found[j]) res |= dfs3(j);
		}	
		ret.push_back(res ? 1 : 0);
	}
	return ret;
}
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 1712 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 588 KB 3rd lines differ - on the 8th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 101 ms 2004 KB Output is correct
2 Correct 93 ms 1940 KB Output is correct
3 Correct 90 ms 1884 KB Output is correct
4 Correct 115 ms 1740 KB Output is correct
5 Correct 128 ms 1732 KB Output is correct
6 Correct 83 ms 1656 KB Output is correct
7 Correct 14 ms 1668 KB Output is correct
8 Correct 39 ms 1760 KB Output is correct
9 Correct 43 ms 1632 KB Output is correct
10 Correct 42 ms 1604 KB Output is correct
11 Incorrect 72 ms 1564 KB 3rd lines differ - on the 89th token, expected: '1', found: '0'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 1572 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 115 ms 1816 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 1712 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -