# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136573 | Lawliet | Wiring (IOI17_wiring) | 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 <bits/stdc++.h>
#define MAX 5010
using namespace std;
int N, M;
int curComponent;
int node[MAX];
bool isCycle[MAX];
bool isSpecial[MAX];
bool ArezouOwn[MAX];
bool BorzouOwn[MAX];
vector<int> grafo[MAX];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v)
{
N = a.size(); M = u.size();
for(int g = 0 ; g < M ; g++)
{
if(u[g] == v[g]) isCycle[ u[g] + 1 ] = true;
else grafo[ u[g] + 1 ].push_back( v[g] + 1 );
}
for(int g = 0 ; g < r.size() ; g++)
isSpecial[ r[g] + 1 ] = true;
for(int g = 0 ; g < N ; g++)
{
if(a[g] == 1) ArezouOwn[g + 1] = true;
else BorzouOwn[g + 1] = true;
}
vector<int> ans;
for(int curStation = 1 ; curStation <= N ; curStation++)
{
int aux = curStation;
bool flag = false;
while( true )
{
if(isCycle[aux] && isSpecial[aux] && ArezouOwn[aux])
{
ans.push_back(1); flag = true;
break;
}
if(isCycle[aux] && !isSpecial[aux] && BorzouOwn[aux])
{
ans.push_back(0); flag = true;
break;
}
if(grafo[aux].empty()) break;
aux = grafo[aux].back();
}
if(!flag) ans.push_back( 0 );
}
return ans;
}
/*int main()
{
int nn, mm, n1, n2;
scanf("%d %d",&nn,&mm);
vector<int> v1, v2;
vector<int> uu, vv;
for(int g = 0 ; g < nn ; g++)
v1.push_back( 1 );
v2.push_back(0);
//v2.push_back(3);
v2.push_back(5);
for(int g = 0 ; g < mm ; g++)
{
scanf("%d %d",&n1,&n2);
n1--;n2--;
uu.push_back( n1 );
vv.push_back( n2 );
}
vector<int> ans = who_wins(v1 , v2 , uu , vv);
for(int g = 0 ; g < nn ; g++)
printf("%d ",ans[g]);
}*/