Submission #788971

# Submission time Handle Problem Language Result Execution time Memory
788971 2023-07-20T18:51:02 Z benjaminkleyn Werewolf (IOI18_werewolf) C++17
0 / 100
269 ms 61948 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int e[200000];
int par1[200000][20], par2[200000][20];

int find(int u)
{
    return e[u] == u ? u : e[u] = find(e[u]);
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R)
{
    int Q = S.size(), M = X.size();
    vector<int> A(Q, 0);

    for (int i = 0; i < N; i++)
        par1[i][0] = par2[i][0] = i;

    vector<vector<int>> g(N);
    for (int i = 0; i < M; i++)
    {
        g[X[i]].push_back(Y[i]);
        g[Y[i]].push_back(X[i]);
    }

    for (int i = 0; i < N; i++)
        e[i] = i;

    for (int u = 0; u < N; u++)
        for (int v : g[u])
            if (v < u)
            {
                v = find(v);
                e[v] = u;
                par1[v][0] = u;
            }

    for (int i = 0; i < N; i++)
        e[i] = i;

    for (int u = N - 1; u >= 0; u--)
        for (int v : g[u])
            if (v > u)
            {
                v = find(v);
                e[v] = u;
                par2[v][0] = u;
            }

    for (int k = 1; k < 20; k++)
        for (int u = 0; u < N; u++)
        {
            par1[u][k] = par1[par1[u][k-1]][k-1];
            par2[u][k] = par2[par2[u][k-1]][k-1];
        }

    for (int i = 0; i < Q; i++)
    {
        for (int k = 19; k >= 0; k--)
        {
            if (par2[S[i]][k] >= L[i])
                S[i] = par2[S[i]][k];
            if (par1[E[i]][k] <= R[i])
                E[i] = par1[E[i]][k];
        }
        for (int k = 19; k >= 0; k--)
            if (par1[S[i]][k] <= R[i])
                S[i] = par1[S[i]][k];

        A[i] = (S[i] == E[i]);
    }

    return A;
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 269 ms 61948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -