Submission #1304646

#TimeUsernameProblemLanguageResultExecution timeMemory
1304646FaggiToy Train (IOI17_train)C++20
5 / 100
2094 ms327680 KiB
#include <bits/stdc++.h>
#define ll long long
#define sz(x) int(x.size())
#define forn(i, n) for (i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fr first
#define se second
using namespace std;

const int MAXN = 1e5 + 1;

vector<ll> grafo[MAXN];

ll ap[MAXN];
vector<int> ans;
vector<int> A, R;
ll dfs(ll nod, ll pad)
{
    ll win = !A[nod];
    for (auto k : grafo[nod])
    {
        if (k == pad)
            continue;
        if (k != nod && dfs(k, nod) == A[nod])
            win = A[nod];
        if (k == nod && A[nod] == R[nod])
            win = A[nod];
    }
    ans[nod] = win;
    return win;
}

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v)
{

    ll i, n = sz(a), m = sz(u);
    A = a;
    R = r;
    ans.resize(n, 0);
    for (i = 0; i < m; i++)
    {
        grafo[u[i]].pb(v[i]);
        if (v[i] != u[i])
            ap[v[i]]++;
    }
    for (i = 0; i < n; i++)
        if (ap[i] == 0)
            dfs(i, -1);
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...