#include "train.h"
#define dbg(x) cerr<<#x<<": "<<x<<endl
#define here cerr<<"===================================\n"
#include <bits/stdc++.h>
#define ll int
#define sz(a) (ll)(a.size())
#define pb push_back
#define popb pop_back
#define all(a) a.begin(),a.end()
#define llinf 1000000000LL
#define fi first
#define sc second
#define pll pair<ll,ll>
#define endl '\n'
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 5005
ll n,m,it;
vector<ll> ans;
vector<ll> g[maxn];
vector<ll> cur;
bool c[maxn];
bool vis[maxn];
bool naso = 0;
bool ok[maxn];
ll cnt = 0;
ll in[maxn],out[maxn];
void dfs(ll u,ll poc){
vis[u] = 1;
for(ll s : g[u]){
if(c[s]) continue;
if(s==poc){
naso = 1;
return;
}
if(vis[s]) continue;
dfs(s,poc);
if(naso) return;
}
}
void dfs2(ll u,ll poc){
if(c[u]) cnt++;
vis[u] = 1;
for(ll s : g[u]){
if(s==poc&&cnt){
naso = 1;
return;
}
if(vis[s]) continue;
dfs(s,poc);
if(naso) return;
}
if(c[u]) cnt--;
}
void dfs3(ll u){
vis[u] = 1;
for(ll s : g[u]){
if(vis[s]) continue;
dfs3(s);
ok[u]|=ok[s];
}
}
vector<int> who_wins(vector<int> a,vector<int> r,vector<int> u,vector<int> v) {
reverse(all(u)); u.pb(-1); reverse(all(u));
reverse(all(v)); v.pb(-1); reverse(all(v));
reverse(all(r)); r.pb(-1); reverse(all(r));
ll sum = 0; for(ll x : a) sum+=x;
n = sz(a);
m = sz(u)-1;
for(ll i = 1;i<=n;i++) c[i] = r[i];
for(ll i = 1;i<=m;i++){
u[i]++; v[i]++;
ll x = u[i]; ll y = v[i];
g[x].pb(y);
}
if(sum==0){
for(ll i = 1;i<=n;i++){
if(c[i]) continue;
for(ll j = 1;j<=n;j++) vis[j] = 0;
naso = 0;
dfs(i,i);
if(naso) ok[i] = 1;
}
for(ll i = 1;i<=n;i++){
for(ll j = 1;j<=n;j++) vis[j] = 0;
dfs3(i);
}
for(ll i = 1;i<=n;i++) ans.pb(1^ok[i]);
return ans;
}
if(sum==n){
for(ll i = 1;i<=n;i++){
for(ll j = 1;j<=n;j++) vis[j] = 0;
naso = 0;
cnt = 0;
dfs2(i,i);
if(naso) ok[i] = 1;
}
for(ll i = 1;i<=n;i++) ans.pb(ok[i]);
return ans;
}
return {};
}
/*
4 6
0 0 0 0
0 1 0 0
0 1
0 2
0 3
1 2
1 3
2 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
724 KB |
WA in grader: Wrong returned array size |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
WA in grader: Wrong returned array size |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
67 ms |
1256 KB |
3rd lines differ - on the 5th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
648 ms |
1064 KB |
Output is correct |
2 |
Correct |
193 ms |
996 KB |
Output is correct |
3 |
Correct |
361 ms |
1060 KB |
Output is correct |
4 |
Correct |
361 ms |
1100 KB |
Output is correct |
5 |
Correct |
522 ms |
1192 KB |
Output is correct |
6 |
Correct |
425 ms |
1068 KB |
Output is correct |
7 |
Correct |
441 ms |
1120 KB |
Output is correct |
8 |
Correct |
317 ms |
1020 KB |
Output is correct |
9 |
Correct |
22 ms |
1000 KB |
Output is correct |
10 |
Correct |
829 ms |
1236 KB |
Output is correct |
11 |
Correct |
839 ms |
1252 KB |
Output is correct |
12 |
Correct |
789 ms |
1384 KB |
Output is correct |
13 |
Correct |
640 ms |
1140 KB |
Output is correct |
14 |
Correct |
386 ms |
1044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
980 KB |
WA in grader: Wrong returned array size |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
724 KB |
WA in grader: Wrong returned array size |
2 |
Halted |
0 ms |
0 KB |
- |