# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1089030 |
2024-09-15T19:21:20 Z |
urd05 |
Toy Train (IOI17_train) |
C++17 |
|
7 ms |
3164 KB |
#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++) {
if (deg[i]==0) {
q.push(i);
}
}
while (!q.empty()) {
int now=q.front();
q.pop();
vis[now]=true;
for(int nt:adj[now]) {
deg[nt]--;
if (deg[nt]==0) {
q.push(nt);
}
}
}
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++) {
assert(!vis[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 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
2140 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Runtime error |
1 ms |
1116 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
3164 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
2652 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
2908 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
2140 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |