답안 #584686

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584686 2022-06-27T19:50:47 Z 1ne 장난감 기차 (IOI17_train) C++14
0 / 100
1051 ms 1352 KB
#include "train.h"
#include<bits/stdc++.h>
using namespace std;
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	int n = (int)a.size();
	int m = (int)u.size();
	vector<int>ans(n);
	vector<vector<int>>adj(n);
	for (int i = 0;i<m;++i){
		adj[u[i]].push_back(v[i]);
	}
	vector<bool>in_cycle(n,false);
	vector<bool>visited(n,false);
	for (int i = 0;i<n;++i){
		if (!r[i])continue;
		vector<int>bucket;
		for (int j = 0;j<n;++j)visited[j] = false;
		function<void(int)>dfs = [&](int u){
			if (visited[u]){
				if (u == i){
					for (auto x:bucket){
						in_cycle[x] = true;
					}
				}
				return;
			}
			bucket.push_back(u);
			visited[u] = true;
			for (auto x:adj[u]){
				dfs(x);
			}
			bucket.pop_back();
		};
		dfs(i);
	}
	for (int i = 0;i<n;++i){
		visited[i] = false;
	}
	for (int i = 0;i<m;++i){
		if (u[i] == v[i] && r[u[i]]){
			in_cycle[u[i]] = true;
		}
	}
	for (int i = 0;i<n;++i){
		if (in_cycle[i]){
			visited[i] = true;
			ans[i] = true;
		}
	}
	
	function<int(int)>dfs2 = [&](int u){
		if (visited[u])return ans[u];
		visited[u] = true;
		int v = 0;
		for (auto x:adj[u]){
			v|=dfs2(x);
		}
		return ans[u] = v;
	};
	for (int i = 0;i<n;++i){
		if (!visited[i]){
			ans[i] = dfs2(i);
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 196 ms 1228 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 8th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1236 KB Output is correct
2 Correct 45 ms 1188 KB Output is correct
3 Correct 90 ms 1248 KB Output is correct
4 Correct 422 ms 1352 KB Output is correct
5 Correct 58 ms 1172 KB Output is correct
6 Correct 94 ms 1028 KB Output is correct
7 Correct 305 ms 1108 KB Output is correct
8 Incorrect 6 ms 980 KB 3rd lines differ - on the 305th token, expected: '1', found: '0'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1051 ms 1076 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1108 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 196 ms 1228 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -