# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
294381 | eohomegrownapps | Towns (IOI15_towns) | C++14 | 0 ms | 0 KiB |
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 "train.h"
#include <bits/stdc++.h>
using namespace std;
int n,m;
vector<vector<int>> adjlist;
vector<vector<int>> revadjlist;
vector<int> aowns;
vector<int> charging;
vector<int> used; // 0 - eliminated, 1 - unvisited, 2 - in f
vector<int> awins;
void genSet(){
vector<int> numconnected(n,0);
queue<int> q;
for (int i = 0; i<n; i++){
if (used[i]==2){
q.push(i);
}
}
while (q.size()>0){
int f = q.front();
q.pop();
for (int i : revadjlist[f]){
if (used[i]!=1){continue;}
numconnected[i]++;
if (aowns[i]||((!aowns[i])&&numconnected[i]==adjlist[i].size())){
// i is in s
used[i]=2;
q.push(i);
}
}
}
}
bool eliminate(){
for (int i = 0; i<n; i++){
if (used[i]!=0){
used[i]=1;
}
if (charging[i]){
used[i]=2;
}
}
genSet();
bool ahasall = true;
for (int i = 0; i<n; i++){
if (used[i]==1){
used[i]=2;
ahasall=false;
} else if (used[i]==2){
used[i]=1;
}
}
if (ahasall){
for (int i = 0; i<n; i++){
if (used[i]==1){
awins[i]=1;
}
}
return true;
}
genSet();
for (int i = 0; i<n; i++){
if (used[i]==2){
awins[i]=0;
used[i]=0;
}
}
return false;
}
std::vector<int> who_wins(std::vector<int> _aowns, std::vector<int> _charging, std::vector<int> u, std::vector<int> v) {
aowns=_aowns;
charging=_charging;
n=aowns.size();
m=u.size();
//cout<<"blah"<<endl;
//cout<<n<<endl;
adjlist.resize(n);
revadjlist.resize(n);
for (int i = 0; i<m; i++){
//cout<<u[i]<<' '<<v[i]<<endl;
adjlist[u[i]].push_back(v[i]);
revadjlist[v[i]].push_back(u[i]);
}
//cout<<"bleh"<<endl;
awins.resize(n);
used.resize(n,1);
while (!eliminate()){
continue;
}
return awins;
}