#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());
vi gotov(5005, false), t;
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 vis[5005], deg[5005];
vi f(int 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(int, vi)':
train.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int j = 0; j < adjList[i].size(); j++){
| ~~^~~~~~~~~~~~~~~~~~~
train.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < x.size(); i++)
| ~~^~~~~~~~~~
train.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i = 0; i < adjList[curr].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~~~~~
train.cpp: In function 'vi who_wins(vi, vi, vi, vi)':
train.cpp:90:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for (int i = 0; i < graph.size(); i++)
| ~~^~~~~~~~~~~~~~
train.cpp:99:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | for (int i = 0; i < f_b.size(); i++)
| ~~^~~~~~~~~~~~
train.cpp:106:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for (int i = 0; i < graph.size(); i++)
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
1408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
768 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
1920 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
1920 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
1408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |