Submission #702995

# Submission time Handle Problem Language Result Execution time Memory
702995 2023-02-25T12:21:07 Z Abrar_Al_Samit Toy Train (IOI17_train) C++17
0 / 100
31 ms 1748 KB
#include<bits/stdc++.h>
using namespace std;

#define vi vector<int>

const int nax = 5000;
vi g[nax], gt[nax];
int n, m;
vector<int>stk;
int vis[nax];
bool cyc[nax];

void dfs(int v) {
	if(vis[v]==1) {
		for(int i=stk.size()-1; ; --i) {
			cyc[stk[i]] = true;
			if(stk[i]==v) break;
		}
		return;
	}
	stk.push_back(v);
	vis[v] = 1;

	for(int to : g[v]) {
		if(vis[to]!=2) {
			dfs(to);
		}
	}
	vis[v] = 2;
	stk.pop_back();
}
vi who_wins(vi a, vi r, vi u, vi 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]);
	}

	for(int i=0; i<n; ++i) if(!vis[i]) {
		dfs(i);
	}
	queue<int>q;
	vi ret(n);

	for(int i=0; i<n; ++i) if(r[i] && cyc[i]) {
		q.push(i);
		ret[i] = 1;
	}
	while(!q.empty()) {
		int v = q.front();
		q.pop();

		for(int to : gt[v]) {
			if(!ret[to]) {
				ret[to] = 1;
				q.push(to);
			}
		}
	}


	// for(int i=0; i<n; ++i) if(r[i] && a[i]) {
	// 	bool self_loop = false;
	// 	for(int to : g[i]) {
	// 		self_loop |= to==i;
	// 	}
	// 	if(self_loop) {
	// 		q.push(i);
	// 		ret[i] = 1;
	// 	}
	// }

	// for(int i=0; i<n; ++i) if(r[i] && !a[i]) {
	// 	if(g[i].size()==1 && g[i][0]==i) {
	// 		ret[i] = 1;
	// 		q.push(i);
	// 	}
	// }


	// while(!q.empty()) {
	// 	int v = q.front();
	// 	q.pop();

	// 	if(!r[v] && !a[v]) {
	// 		bool self_loop = false;
	// 		for(int to : g[v]) {
	// 			self_loop |= to==v;
	// 		}
	// 		if(self_loop) {
	// 			ret[v] = 0;
	// 			continue;
	// 		}
	// 	}

	// 	for(int to : gt[v]) if(!ret[to]) {
	// 		ret[to] = 1;
	// 		q.push(to);
	// 	}
	// }
	return ret;
}
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 468 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 6 ms 1712 KB Output is correct
2 Correct 6 ms 1748 KB Output is correct
3 Correct 7 ms 1644 KB Output is correct
4 Correct 17 ms 1720 KB Output is correct
5 Correct 19 ms 1672 KB Output is correct
6 Correct 11 ms 1592 KB Output is correct
7 Correct 9 ms 1580 KB Output is correct
8 Correct 7 ms 1588 KB Output is correct
9 Correct 6 ms 1552 KB Output is correct
10 Correct 7 ms 1564 KB Output is correct
11 Correct 7 ms 1492 KB Output is correct
12 Correct 8 ms 1416 KB Output is correct
13 Correct 31 ms 1708 KB Output is correct
14 Incorrect 30 ms 1740 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 1492 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 21 ms 1700 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 4 ms 1364 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -