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<bits/stdc++.h>
#include "train.h"
using namespace std;
const int MAX_SOM=5000+5;
int nbSom,nbAre;
vector<int> rep,possed,charg;
vector<int> adjaTrans[MAX_SOM];
int degSort[MAX_SOM];
int pb[MAX_SOM],enCours[MAX_SOM];
void DFS(int pos) {
if (pb[pos]==0) {
pb[pos]=1;
for (int i:adjaTrans[pos]) {
if (possed[i]==1) {
DFS(i);
}
else {
degSort[i]--;
if (degSort[i]==0) {
DFS(i);
}
}
}
}
}
void DFS2(int pos) {
if (rep[pos]==1) {
rep[pos]=0;
enCours[pos]=0;
for (int i:adjaTrans[pos]) {
if (possed[i]==0) {
DFS2(i);
}
else {
degSort[i]--;
if (degSort[i]==0) {
DFS2(i);
}
}
}
}
}
vector<int> who_wins(vector<int> a,vector<int> r,vector<int> u,vector<int> v) {
nbSom=a.size();
nbAre=u.size();
possed=a;
charg=r;
rep.resize(nbSom,1);
int fini=0;
for (int i=0;i<nbSom;i++) {
enCours[i]=1;
}
while (fini==0) {
for (int i=0;i<nbSom;i++) {
degSort[i]=0;
pb[i]=0;
adjaTrans[i].clear();
}
for (int i=0;i<nbAre;i++) {
if (enCours[u[i]]==1 and enCours[v[i]]==1) {
adjaTrans[v[i]].push_back(u[i]);
degSort[u[i]]++;
}
}
for (int i=0;i<nbSom;i++) {
if (enCours[i]==1 and charg[i]==1) {
DFS(i);
}
}
fini=1;
for (int i=0;i<nbSom;i++) {
if (enCours[i]==1 and pb[i]==0) {
fini=0;
}
}
if (fini==0) {
for (int i=0;i<nbSom;i++) {
if (pb[i]==0) {
DFS2(i);
}
}
}
}
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... |