# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
263617 | arayi | Toy Train (IOI17_train) | C++17 | 1474 ms | 4088 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 <vector>
#include <queue>
#include <algorithm>
#define ad push_back
using namespace std;
const int N = 5e4 + 30;
int n;
vector <int> g[N], g1[N];
vector<int> col, r;
int sm[N], need[N];
void smth()
{
for (int i = 0; i < n; i++)
sm[i] = 0, col[i] = 0;
queue <int> q;
for (int i = 0; i < n; i++)
{
if(r[i])
{
for(auto p : g1[i])
{
sm[p]++;
if(sm[p] == need[p]) q.push(p);
}
}
}
while(!q.empty())
{
int v = q.front();
q.pop();
col[v] = 1;
if(r[v]) continue;
for(auto p : g1[v])
{
sm[p]++;
if(sm[p] == need[p]) q.push(p);
}
}
}
vector <int> who_wins(vector<int> a, vector<int> R, vector<int> u, vector<int> v) {
n = a.size();
r = R;
for (int i = 0; i < u.size(); i++)
{
g[u[i]].ad(v[i]);
g1[v[i]].ad(u[i]);
}
for (int i = 0; i < n; i++)
{
col.ad(0);
if(a[i]) need[i] = 1;
else need[i] = (int)g[i].size();
}
for (int i = 0; i < n; i++)
{
smth();
for (int j = 0; j < n; j++)
{
if(r[j] && !col[j]) r[j] = 0;
}
}
return col;
}
Compilation message (stderr)
# | 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... |