#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
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 |
1 |
Incorrect |
7 ms |
1272 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
2 ms |
1272 KB |
Output is correct |
3 |
Incorrect |
2 ms |
1272 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1772 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
1772 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1772 KB |
Output is correct |
2 |
Correct |
12 ms |
1772 KB |
Output is correct |
3 |
Correct |
14 ms |
1772 KB |
Output is correct |
4 |
Correct |
16 ms |
1844 KB |
Output is correct |
5 |
Correct |
3 ms |
1844 KB |
Output is correct |
6 |
Correct |
7 ms |
1844 KB |
Output is correct |
7 |
Correct |
13 ms |
1844 KB |
Output is correct |
8 |
Correct |
8 ms |
1844 KB |
Output is correct |
9 |
Correct |
14 ms |
1844 KB |
Output is correct |
10 |
Correct |
4 ms |
1844 KB |
Output is correct |
11 |
Correct |
8 ms |
1844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
1272 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |