#include "train.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uset = unordered_set<int>;
const int nmax = 5e3 + 5;
vector<int> g[nmax], t[nmax];
vector<int> own, charge, rez, degree;
int n, m;
int cnt = 0;
void solve(uset& V) {
if(V.size() == 0)
return;
uset S;
for(auto x : V) {
if(charge[x])
S.insert(x);
for(int i = 0; i < g[x].size(); i++) {
if(V.count(g[x][i]) == 0)
swap(g[x][i], g[x].back()), g[x].pop_back();
}
for(int i = 0; i < t[x].size(); i++) {
if(V.count(t[x][i]) == 0)
swap(t[x][i], t[x].back()), t[x].pop_back();
}
}
if(S.size() == 0) {
for(auto x : V)
rez[x] = 0;
return;
}
for(auto x : V) {
if(charge[x])
degree[x] = 0;
if(own[x] == 1)
degree[x] = 1;
else
degree[x] = g[x].size();
}
queue<int> que;
function<void()> markall = [&]() {
while (!que.empty()) {
int node = que.front();
for(auto x : t[node]) {
degree[x]--;
if(degree[x] == 0 && !S.count(x))
S.insert(x),
que.push(x);
}
que.pop();
}
que = queue<int>();
return;
};
for(auto x : S)
que.push(x);
markall();
if(S.size() == V.size()) {
for(auto x : V)
rez[x] = 1;
return;
}
uset notS;
for(auto x : V)
if(S.count(x) == 0)
notS.insert(x);
for(auto x : V) {
if(notS.count(x) == 1)
degree[x] = 0;
if(own[x] == 0)
degree[x] = 1;
else
degree[x] = g[x].size();
}
swap(S, notS);
for(auto x : S)
que.push(x);
markall();
for(auto x : S)
rez[x] = 0, // formality
V.erase(x);
solve(V);
}
std::vector<int> who_wins(std::vector<int> A, std::vector<int> R, std::vector<int> U, std::vector<int> V) {
own = move(A);
charge = move(R);
n = own.size();
m = U.size();
degree.resize(n, 0);
rez.resize(n, 0);
for(int i = 0; i < m; i++)
g[U[i]].push_back(V[i]),
t[V[i]].push_back(U[i]);
uset Vertex;
for(int i = 0; i < n; i++)
Vertex.insert(i);
solve(Vertex);
return rez;
}
Compilation message
train.cpp: In function 'void solve(uset&)':
train.cpp:22:22: 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 < g[x].size(); i++) {
| ~~^~~~~~~~~~~~~
train.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = 0; i < t[x].size(); i++) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1876 KB |
Output is correct |
2 |
Correct |
12 ms |
2516 KB |
Output is correct |
3 |
Correct |
9 ms |
2260 KB |
Output is correct |
4 |
Correct |
10 ms |
2132 KB |
Output is correct |
5 |
Correct |
8 ms |
1964 KB |
Output is correct |
6 |
Correct |
8 ms |
2060 KB |
Output is correct |
7 |
Correct |
6 ms |
1580 KB |
Output is correct |
8 |
Correct |
9 ms |
2388 KB |
Output is correct |
9 |
Correct |
7 ms |
1876 KB |
Output is correct |
10 |
Correct |
6 ms |
1748 KB |
Output is correct |
11 |
Correct |
5 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
544 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Incorrect |
1 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
543 ms |
88684 KB |
Output is correct |
2 |
Correct |
1029 ms |
149684 KB |
Output is correct |
3 |
Correct |
1299 ms |
177148 KB |
Output is correct |
4 |
Correct |
9 ms |
1876 KB |
Output is correct |
5 |
Incorrect |
12 ms |
2176 KB |
3rd lines differ - on the 11th token, expected: '0', found: '1' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1748 KB |
Output is correct |
2 |
Correct |
9 ms |
1876 KB |
Output is correct |
3 |
Correct |
8 ms |
1876 KB |
Output is correct |
4 |
Correct |
11 ms |
2092 KB |
Output is correct |
5 |
Correct |
11 ms |
1996 KB |
Output is correct |
6 |
Correct |
11 ms |
2048 KB |
Output is correct |
7 |
Correct |
11 ms |
1960 KB |
Output is correct |
8 |
Correct |
9 ms |
1940 KB |
Output is correct |
9 |
Correct |
13 ms |
2004 KB |
Output is correct |
10 |
Correct |
9 ms |
1964 KB |
Output is correct |
11 |
Correct |
9 ms |
1876 KB |
Output is correct |
12 |
Correct |
9 ms |
1876 KB |
Output is correct |
13 |
Correct |
11 ms |
2004 KB |
Output is correct |
14 |
Correct |
9 ms |
2004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1848 KB |
Output is correct |
2 |
Correct |
9 ms |
1748 KB |
Output is correct |
3 |
Correct |
13 ms |
1832 KB |
Output is correct |
4 |
Correct |
10 ms |
1800 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
9 ms |
1448 KB |
Output is correct |
7 |
Correct |
6 ms |
1236 KB |
Output is correct |
8 |
Correct |
6 ms |
1236 KB |
Output is correct |
9 |
Correct |
6 ms |
1236 KB |
Output is correct |
10 |
Correct |
2 ms |
684 KB |
Output is correct |
11 |
Correct |
6 ms |
1200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1876 KB |
Output is correct |
2 |
Correct |
12 ms |
2516 KB |
Output is correct |
3 |
Correct |
9 ms |
2260 KB |
Output is correct |
4 |
Correct |
10 ms |
2132 KB |
Output is correct |
5 |
Correct |
8 ms |
1964 KB |
Output is correct |
6 |
Correct |
8 ms |
2060 KB |
Output is correct |
7 |
Correct |
6 ms |
1580 KB |
Output is correct |
8 |
Correct |
9 ms |
2388 KB |
Output is correct |
9 |
Correct |
7 ms |
1876 KB |
Output is correct |
10 |
Correct |
6 ms |
1748 KB |
Output is correct |
11 |
Correct |
5 ms |
1620 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
544 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Incorrect |
1 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
21 |
Halted |
0 ms |
0 KB |
- |