//#include "train.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[5005];
vector<int> rev[5005];
int n,m;
int deg[5005];
bool vis[5005];
bool chk[5005];//true면 A편편
int dp[5005];
int aa[5005];
int ans(int v) {
if (dp[v]!=-1) {
return dp[v];
}
if (!vis[v]) {
return dp[v]=chk[v];
}
if (aa[v]==0) {
int ret=1;
for(int nt:adj[v]) {
if (ans(nt)==0) {
ret=0;
break;
}
}
return dp[v]=ret;
}
if (aa[v]==1) {
int ret=0;
for(int nt:adj[v]) {
if (ans(nt)==1) {
ret=1;
break;
}
}
return dp[v]=ret;
}
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
n=a.size();
m=u.size();
for(int i=0;i<n;i++) {
aa[i]=a[i];
}
for(int i=0;i<m;i++) {
adj[u[i]].push_back(v[i]);
rev[v[i]].push_back(u[i]);
deg[v[i]]++;
}
queue<int> q;
for(int i=0;i<n;i++) {
deg[i]=0;
if (!vis[i]) {
for(int nt:adj[i]) {
if (!vis[nt]) {
deg[i]++;
}
}
}
}
for(int i=0;i<n;i++) {
if (!vis[i]&&r[i]) {
q.push(i);
chk[i]=true;
}
}
while (!q.empty()) {
int now=q.front();
q.pop();
for(int nt:rev[now]) {
if (chk[nt]||vis[nt]) {
continue;
}
if (a[nt]==1) {
chk[nt]=true;
q.push(nt);
}
else {
deg[nt]--;
if (deg[nt]==0) {
chk[nt]=true;
q.push(nt);
}
}
}
}
vector<int> ret(n);
for(int i=0;i<n;i++) {
ret[i]=-1;
}
for(int i=0;i<n;i++) {
if (!vis[i]&&!chk[i]) {
q.push(i);
}
}
for(int i=0;i<n;i++) {
deg[i]=0;
if (!vis[i]) {
for(int nt:adj[i]) {
if (!vis[nt]) {
deg[i]++;
}
}
}
}
while (!q.empty()) {
int now=q.front();
q.pop();
for(int nt:rev[now]) {
if (!chk[nt]||vis[nt]) {
continue;
}
if (a[nt]==0) {
chk[nt]=false;
q.push(nt);
}
else {
deg[nt]--;
if (deg[nt]==0) {
chk[nt]=false;
q.push(nt);
}
}
}
}
memset(dp,-1,sizeof(dp));
for(int i=0;i<n;i++) {
ret[i]=ans(i);
}
return ret;
}
Compilation message
train.cpp: In function 'int ans(int)':
train.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
41 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1116 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Incorrect |
0 ms |
604 KB |
3rd lines differ - on the 4th token, expected: '0', found: '1' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1628 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1368 KB |
Output is correct |
2 |
Correct |
5 ms |
1628 KB |
Output is correct |
3 |
Correct |
5 ms |
1720 KB |
Output is correct |
4 |
Correct |
6 ms |
1628 KB |
Output is correct |
5 |
Correct |
5 ms |
1628 KB |
Output is correct |
6 |
Correct |
5 ms |
1628 KB |
Output is correct |
7 |
Correct |
5 ms |
1624 KB |
Output is correct |
8 |
Correct |
5 ms |
1716 KB |
Output is correct |
9 |
Correct |
5 ms |
1628 KB |
Output is correct |
10 |
Correct |
6 ms |
1628 KB |
Output is correct |
11 |
Correct |
5 ms |
1628 KB |
Output is correct |
12 |
Correct |
5 ms |
1720 KB |
Output is correct |
13 |
Correct |
6 ms |
1628 KB |
Output is correct |
14 |
Correct |
5 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1368 KB |
Output is correct |
2 |
Correct |
6 ms |
1596 KB |
Output is correct |
3 |
Correct |
6 ms |
1628 KB |
Output is correct |
4 |
Correct |
5 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
3 ms |
1108 KB |
Output is correct |
7 |
Correct |
3 ms |
1372 KB |
Output is correct |
8 |
Incorrect |
3 ms |
1372 KB |
3rd lines differ - on the 5th token, expected: '0', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1116 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |