Submission #1304770

#TimeUsernameProblemLanguageResultExecution timeMemory
1304770FaggiToy Train (IOI17_train)C++20
5 / 100
2096 ms1604 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 dp[MAXN], act[MAXN];
bool vis[MAXN];
vector<int>R, A;
bool dfs(ll nod, ll prof)
{
    dp[prof]=dp[prof]+R[nod];
    act[nod]=prof;
    vis[nod]=1;
    bool mi=1, ma=0;
    for(auto k:grafo[nod])
    {
        if(vis[k])
        {
            if(dp[prof]-dp[act[k]]>0||R[k])
                ma=1;
            else
                mi=0;
        }
        else
        {
            if(dfs(k,prof+1))
                ma=1;
            else
                mi=0;
        }
    }
    dp[prof]=0;
    act[nod]=0;
    vis[nod]=0;
    if(A[nod]==1)
        return ma;
    return mi;
}

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v)
{
    A=a;
    R=r;
    ll i, n = sz(a), m = sz(u);
    for(i=0; i<m; i++)
        grafo[u[i]].pb(v[i]);
    vector<int>ans(n,0);
    for(i=0; i<n; i++)
        ans[i]=dfs(i,0);
    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...