This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "train.h"
#include<bits/stdc++.h>
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
#define mp make_pair
#define F first
#define S second
#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
#define eb emplace_back
using namespace std;
typedef long long ll;
using pii = pair<int, int>;
const ll MAX = 1LL << 60;
ostream& operator<<(ostream& o, pii p){
return o << '(' << p.F << ',' << p.S << ')';
}
int n, m;
vector<vector<int>> g, rg;
vector<int> t;
vector<bool> vst;
void dfs1(int now){
vst[now] = true;
for(int i : rg[now]){
if(!vst[i]) dfs1(i);
}
t.eb(now);
}
vector<int> scc, sz;
void dfs2(int now, int id){
scc[now] = id;
sz[id]++;
for(int i : g[now]){
if(scc[i] == -1) dfs2(i, id);
}
}
vector<bool> c;
bool ok = false;
void dfs(int now){
vst[now] = true;
if(c[now]) ok = true;
for(int i : g[now]){
if(!vst[i]) dfs(i);
}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = a.size(), m = u.size();
c.resize(n);
g.resize(n);
rg.resize(n);
for(int i = 0; i < m; i++){
if(u[i] == v[i]){
c[u[i]] = true;
continue;
}
g[u[i]].eb(v[i]);
rg[v[i]].eb(u[i]);
}
vst.resize(n);
scc.resize(n, -1);
sz.resize(n);
for(int i = 0; i < n; i++){
if(!vst[i]) dfs1(i);
}
reverse(iter(t));
int ts = 0;
for(int i : t){
if(scc[i] != -1) continue;
dfs2(i, ts++);
}
for(int i = 0; i < n; i++){
if(sz[scc[i]] > 1) c[i] = true;
if(!r[i]) c[i] = false;
}
//printv(c, cerr);
vector<int> ans(n);
for(int i = 0; i < n; i++){
ok = false;
fill(iter(vst), false);
//cerr << "test " << i << "\n";
dfs(i);
ans[i] = ok;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |