This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |