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>
using namespace std;
const int maxn = 5e3 + 5;
int n,m;
int own[maxn], good[maxn];
vector<int> way[maxn], yaw[maxn];
int vis[maxn], deg[maxn], cyc[maxn];
queue<int> q;
int res[maxn];
void getcyc() {
// printf("solve\n");
for(int i=0;i<n;i++) vis[i] = deg[i] = 0;
for(int i=0;i<n;i++) if(good[i]) q.push(i);
while(!q.empty()) {
int v = q.front(); q.pop();
if(good[v] && vis[v]) continue;
for(auto u : yaw[v]) {
if(own[u]) {
if(!vis[u]) {
vis[u] = 1;
q.push(u);
}
}
else {
deg[u]++;
if(!vis[u] && deg[u]==way[u].size()) {
vis[u] = 1;
q.push(u);
}
}
}
}
for(int i=0;i<n;i++) {
if(good[i] && vis[i]) {
cyc[i] = 1;
// printf("cyc %d\n",i);
}
}
}
void solve() {
for(int i=0;i<n;i++) vis[i] = deg[i] = 0;
for(int i=0;i<n;i++) {
if(cyc[i]) {
vis[i] = 1;
q.push(i);
}
}
while(!q.empty()) {
int v = q.front(); q.pop();
for(auto u : yaw[v]) {
if(own[u]) {
if(!vis[u]) {
vis[u] = 1;
q.push(u);
}
}
else {
deg[u]++;
if(!vis[u] && deg[u]==way[u].size()) {
vis[u] = 1;
q.push(u);
}
}
}
}
for(int i=0;i<n;i++) res[i] = vis[i];
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = (int)a.size();
for(int i=0;i<n;i++) {
own[i] = a[i];
good[i] = r[i];
}
m = (int)u.size();
for(int i=0;i<m;i++) {
way[u[i]].push_back(v[i]);
yaw[v[i]].push_back(u[i]);
}
getcyc();
solve();
vector<int> ret;
for(int i=0;i<n;i++) ret.push_back(res[i]);
return ret;
}
Compilation message (stderr)
train.cpp: In function 'void getcyc()':
train.cpp:32:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(!vis[u] && deg[u]==way[u].size()) {
~~~~~~^~~~~~~~~~~~~~~
train.cpp: In function 'void solve()':
train.cpp:66:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(!vis[u] && deg[u]==way[u].size()) {
~~~~~~^~~~~~~~~~~~~~~
# | 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... |