#include <iostream>
#include <vector>
using namespace std;
const int MAX_SOMMET = 5042;
bool gagnant[MAX_SOMMET] = {0};
int qui[MAX_SOMMET];
bool recharge[MAX_SOMMET];
int nbSommet, nbArete;
vector<int> adj[MAX_SOMMET];
int nbSortant[MAX_SOMMET] = {0};
bool acces[MAX_SOMMET] = {0};
int premier = 1;
void dfs(int sommet, int type) {
if((type == 1 && acces[sommet]) || (type == 2 && gagnant[sommet]))
return;
if(!premier && type == 1)
acces[sommet] = 1;
if(type == 2)
gagnant[sommet] = 1;
premier = 0;
for(auto voisin : adj[sommet]) {
if(qui[voisin] == 1)
dfs(voisin, type);
else {
nbSortant[voisin]--;
if(nbSortant[voisin] == 0)
dfs(voisin, type);
}
}
}
void resetSortant() {
premier = 1;
for(int sommet = 0; sommet < nbSommet; sommet++) {
nbSortant[sommet] = 0;
acces[sommet] = 0;
}
for(int sommet = 0; sommet < nbSommet; sommet++) {
for(auto voisin : adj[sommet]) {
nbSortant[voisin]++;
}
}
}
vector<int> rep;
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
nbSommet = a.size();
nbArete = u.size();
for(int i = 0; i < nbSommet; i++) {
gagnant[i] = 0;
qui[i] = a[i];
recharge[i] = r[i];
}
for(int id = 0; id < nbArete; id++) {
adj[v[id]].push_back(u[id]);
}
int nbPerdu = 0;
resetSortant();
do {
nbPerdu = 0;
resetSortant();
for(int sommet = 0; sommet < nbSommet; sommet++) {
if(recharge[sommet]) {
dfs(sommet, 1);
premier = 1;
}
}
for(int sommet = 0; sommet < nbSommet; sommet++) {
if(recharge[sommet] && !acces[sommet]) {
nbPerdu++;
recharge[sommet] = 0;
}
}
} while(nbPerdu > 0);
resetSortant();
for(int sommet = 0; sommet < nbSommet; sommet++) {
if(recharge[sommet])
dfs(sommet, 2);
}
for(int sommet = 0; sommet < nbSommet; sommet++) {
rep.push_back(gagnant[sommet]);
//cout << gagnant[sommet] <<" ";
}
return rep;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
852 KB |
3rd lines differ - on the 22nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
1300 KB |
Output is correct |
2 |
Correct |
204 ms |
1504 KB |
Output is correct |
3 |
Correct |
289 ms |
1508 KB |
Output is correct |
4 |
Correct |
7 ms |
1364 KB |
Output is correct |
5 |
Correct |
11 ms |
1380 KB |
Output is correct |
6 |
Correct |
10 ms |
1252 KB |
Output is correct |
7 |
Correct |
11 ms |
1252 KB |
Output is correct |
8 |
Correct |
9 ms |
1244 KB |
Output is correct |
9 |
Correct |
7 ms |
1208 KB |
Output is correct |
10 |
Correct |
11 ms |
1236 KB |
Output is correct |
11 |
Correct |
6 ms |
1236 KB |
Output is correct |
12 |
Correct |
9 ms |
1248 KB |
Output is correct |
13 |
Correct |
7 ms |
1464 KB |
Output is correct |
14 |
Correct |
7 ms |
1492 KB |
Output is correct |
15 |
Correct |
8 ms |
1444 KB |
Output is correct |
16 |
Correct |
7 ms |
1492 KB |
Output is correct |
17 |
Correct |
10 ms |
1476 KB |
Output is correct |
18 |
Correct |
364 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
980 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1076 KB |
Output is correct |
2 |
Correct |
8 ms |
1236 KB |
Output is correct |
3 |
Correct |
7 ms |
1132 KB |
Output is correct |
4 |
Correct |
6 ms |
1108 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
8 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
5 ms |
820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
852 KB |
3rd lines differ - on the 22nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |