#include "train.h"
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define N 100010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <int, int>
#define sz(a) int(a.size())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}
int n, m;
int vis[N];
int Ch[N];
map <pii, int> M;
vector <int> E[N], v, c;
void dfs(int nd, int pr)
{
v.pb(nd);
vis[nd] = vis[pr]+1;
if(Ch[nd] == 1) c.pb(nd);
for(auto i: E[nd]) {
if(vis[i]) {
int ok = 1;
if(c.empty() || vis[c.back()] < vis[i]) ok = 0;
v.pb(i);
int sz = v.size();
for(int h = 0; h < sz-1; h++) {
if(vis[v[h]] < vis[i]) continue;
M[{v[h], v[h+1]}] = max(ok, M[{v[h], v[h+1]}]);
}
v.pop_back();
continue;
}
dfs(i, nd);
}
vis[nd] = 0;
v.pop_back();
if(Ch[nd] == 1) c.pop_back();
}
vector <int> who_wins(vector <int> a, vector <int> r, vector <int> u, vector <int> v)
{
n = sz(a), m = sz(u);
for(int i = 0; i < n; i++) Ch[i] = r[i];
for(int i = 0; i < m; i++) E[u[i]].pb(v[i]);
dfs(0, -1);
// for(int i = 0; i < m; i++)
// cout << M[{u[i], v[i]}] << " ";
int A[N];
memset(A, 0, sizeof(A));
for(int i = 0; i < n; i++) {
if(a[i] == 1) continue;
int ok = 1;
for(auto h: E[i]) if(M[{i, h}] == 0) ok = 0;
if(ok == 0)
for(auto h: E[i]) M[{i, h}] = M[{h, i}] = 0;
A[i] = ok;
}
for(int i = 0; i < n; i++) {
if(a[i] == 0) continue;
int ok = 0;
for(auto h: E[i]) if(M[{i, h}] == 1 || A[h] == 1) ok = 1;
A[i] = ok;
}
vector <int> ret;
for(int i = 0; i < n; i++) ret.pb(A[i]);
return ret;
}
Compilation message
train.cpp:23: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
23 | #pragma GCC optimization ("O3")
|
train.cpp:24: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
24 | #pragma GCC optimization ("unroll-loops")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
4736 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
3072 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2025 ms |
3328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2045 ms |
3960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2045 ms |
3704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
4736 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |