#include <bits/stdc++.h>
//#include "train.h"
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
const int nax = 5004;
const int MOD = 1e9 + 7;
int n, m ;
vi adj[nax], rev_adj[nax];
int siz[nax];
set<int> cur;
int cnt[nax];
int A[nax];
void rec(int x)
{
if(cur.count(x) != 0)
return ;
cur.insert(x);
for(auto e: rev_adj[x])
{
cnt[e]++;
if(cnt[e] == siz[e])
rec(e);
else if(A[x])
rec(e);
}
}
vi who_wins(vi a, vi r, vi u, vi v)
{
n = a.size();
m = u.size();
for(int i= 0 ; i < n; i++)
A[i] = a[i];
for(int i= 0; i < m; i ++)
{
adj[u[i]].pb(v[i]);
rev_adj[v[i]].pb(u[i]);
}
for(int i = 0 ; i < n; i ++ )
siz[i] = (int)(adj[i].size());
vi ans(n, 0);
vi chrg;
for(int i= 0 ; i < n;i ++)
if(r[i])
chrg.pb(i);
int sz = chrg.size();
if(sz == 0)
return ans;
for(int mask = 1; mask < (1 << sz); mask ++)
{
vi org;
for(int i= 0; i < sz; i ++)
if((1 << i) & mask)
org.pb(chrg[i]);
cur.clear();
for(int i= 0 ; i < n;i ++)
cnt[i] = 0 ;
for(auto e: org)
{
rec(e);
}
bool flag= true;
for(auto e: org)
{
if(a[e])
{
if(cnt[e] == 0)
flag = false;
}
if(!a[e] && (cnt[e] != siz[e]))
flag = false;
}
if(flag)
{
for(auto e: cur)
ans[e] = 1;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1058 ms |
1208 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2056 ms |
2016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2078 ms |
1508 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1384 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1058 ms |
1208 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |