Submission #851597

#TimeUsernameProblemLanguageResultExecution timeMemory
85159712345678Tropical Garden (IOI11_garden)C++17
49 / 100
692 ms2880 KiB
#include "garden.h"
#include "gardenlib.h"
#include "bits/stdc++.h"

using namespace std;

const int nx=1e3+5;
int v[nx], vs[nx], ans;

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    for (int i=0; i<N; i++) v[i]=vs[i]=-1;
    for (int i=0; i<M; i++)
    {
        if (v[R[i][0]]==-1) v[R[i][0]]=R[i][1];
        else if (vs[R[i][0]]==-1) vs[R[i][0]]=R[i][1];
        if (v[R[i][1]]==-1) v[R[i][1]]=R[i][0];
        else if (vs[R[i][1]]==-1) vs[R[i][1]]=R[i][0];
    }
    for (int i=0; i<N; i++) if (vs[i]==-1) vs[i]=v[i];
    for (int i=0; i<N; i++)
    {
        int l=i, f=1, k=G[0];
        while (k--)
        {
            if (f)
            {
                if (v[v[l]]==l) f=0;
                else f=1;
                l=v[l];
            }
            else
            {
                if (v[vs[l]]==l) f=0;
                else f=1;
                l=vs[l];
            }
        }
        if (l==P) ans++;
    }
    answer(ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...