#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
#include "train.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
vector<vi> adjList(5005, vi());
vector<bool> gotov(5005, false), t(5005, false);
int n;
vi operator-(vi a, vi b){
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vi res; int j = 0;
for (int i = 0; i < a.size(); i++){
while(j < b.size() && b[j] < a[i])
j++;
if (j == b.size() || b[j] > a[i])
res.push_back(a[i]);
}
return res;
}
int deg[5005];
bool vis[5005];
vi f(bool type, vi x){
for (int i = 0; i < n; i++)
vis[i] = deg[i] = 0;
for (int i = 0; i < n; i++){
if (gotov[i])
continue;
for (int j = 0; j < adjList[i].size(); j++){
int curr = adjList[i][j];
if (!gotov[curr])
deg[curr]++;
}
}
queue<int> q;
for (int i = 0; i < x.size(); i++)
vis[x[i]] = true, q.push(x[i]);
while(!q.empty()){
int curr = q.front();
q.pop();
for (int i = 0; i < adjList[curr].size(); i++){
int k = adjList[curr][i];
if (gotov[k] || vis[k])
continue;
if (t[k] == type)
vis[k] = 1, q.push(k);
else{
deg[k]--;
if (!deg[k])
vis[k] = 1, q.push(k);
}
}
}
vi res;
for (int i = 0; i < n; i++){
if (!gotov[i] && vis[i])
res.push_back(i);
}
return res;
}
vi who_wins(vi a, vi r, vi u, vi v){
n = a.size(); int m = u.size();
for (int i = 0; i < m; i++)
adjList[v[i]].push_back(u[i]);
vi graph;
for (int i = 0; i < n; i++)
graph.push_back(i), t[i] = a[i];
while(!graph.empty()){
vi f_a, f_b;
for (int i = 0; i < graph.size(); i++)
if (r[graph[i]])
f_a.push_back(i);
f_a = f(1, f_a); f_b = f(0, graph - f_a);
if (!f_b.size())
break;
for (int i = 0; i < f_b.size(); i++)
gotov[f_b[i]] = true;
graph = graph - f_b;
}
vi res(n, 0);
for (int i = 0; i < graph.size(); i++)
res[graph[i]] = true;
return res;
}
Compilation message
train.cpp: In function 'vi operator-(vi, vi)':
train.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < a.size(); i++){
| ~~^~~~~~~~~~
train.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | while(j < b.size() && b[j] < a[i])
| ~~^~~~~~~~~~
train.cpp:26:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | if (j == b.size() || b[j] > a[i])
| ~~^~~~~~~~~~~
train.cpp: In function 'vi f(bool, vi)':
train.cpp:38:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
38 | vis[i] = deg[i] = 0;
| ~~~~~~~^~~
train.cpp:43:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int j = 0; j < adjList[i].size(); j++){
| ~~^~~~~~~~~~~~~~~~~~~
train.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int i = 0; i < x.size(); i++)
| ~~^~~~~~~~~~
train.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 0; i < adjList[curr].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~~~~~
train.cpp: In function 'vi who_wins(vi, vi, vi, vi)':
train.cpp:91:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for (int i = 0; i < graph.size(); i++)
| ~~^~~~~~~~~~~~~~
train.cpp:100:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for (int i = 0; i < f_b.size(); i++)
| ~~^~~~~~~~~~~~
train.cpp:107:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for (int i = 0; i < graph.size(); i++)
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
896 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
1276 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1140 KB |
Output is correct |
2 |
Incorrect |
9 ms |
1280 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
1152 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
896 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |