#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define GR(a,n,m) vector<vector<int>> a(n, vector<int>(m, 0));
const int N = 5005;
int n;
bool vis[N];
vector<int> adj[N], rev[N], a;
vector<int> F(vector<int> f, int p){
for(auto x: f){
vis[x] = true;
}
vector<int> ret;
vector<int> deg(n, 0);
for(int i = 0;i < n;i++){
for(auto x: adj[i]){
if(!vis[x])++deg[x];
}
}
while(sz(f) > 0)
{
int u = f.back();
ret.pb(u);
f.pop_back();
for(auto v: rev[u]){
if(!vis[v]){
--deg[v];
if(a[v] == p || !deg[v]){
vis[v] = true;
f.pb(v);
}
}
}
}
return ret;
}
vector<int> who_wins(vector<int> tempa, vector<int> r, vector<int> u, vector<int> v){
n = sz(tempa);
int M = sz(u);
a = tempa;
for(int i = 0;i < M;i++){
adj[u[i]].pb(v[i]);
rev[v[i]].pb(u[i]);
}
vector<int> ans(n, 0);
while(true)
{
vector<int> rm, c, fA;
for(int i = 0;i < n;i++){
if(vis[i])continue;
if(r[i])c.pb(i);
rm.pb(i);
}
fA = F(c, 1);
if(sz(rm) == sz(c)){
for(auto x: rm)ans[x] = 1;
break;
}
vector<int> s, fAA(n, 0);
for(auto x: fA)fAA[x] = 1;
for(auto x: rm){
vis[x] = false;
if(!fAA[x])s.pb(x);
}
vector<int> fB = F(s, 0);
if(sz(fB) == sz(rm))break;
}
return ans;
}
/*
void solve()
{
int n, m;
cin >> n >> m;
vector<int> aa(n), rr(n), uu(m), vv(m);
forn(i,n)cin>>aa[i];
forn(i,n)cin>>rr[i];
forn(i,m)cin>>uu[i];
forn(i,m)cin>>vv[i];
vector<int> rasp = who_wins(aa,rr,uu,vv);
for(auto x: rasp)cout << x << " ";
}
int32_t main()
{
fastio;
int t = 1;
//cin >> t;
while(t--)
{
solve();
}
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
1116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2075 ms |
1484 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
1356 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
1484 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
1116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |