이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |