Submission #1226009

#TimeUsernameProblemLanguageResultExecution timeMemory
1226009kl0989e게임 (IOI14_game)C++20
42 / 100
1097 ms9432 KiB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()

const int maxn=1510;

int n;
vector<vi> graph(maxn,vi(maxn,-1));
vi head(maxn);
vi seen(maxn,0);
int s=0;

int get(int a) {
    return (a==head[a]?a:head[a]=get(head[a]));
}

void initialize(int _n) {
    n=_n;
}

void dfs(int cur) {
    seen[cur]=1;
    s++;
    for (int i=0; i<n; i=get(i)+1) {
        if (!seen[i] && graph[cur][i]!=0) {
            if (i!=n-1 && head[i+1]!=i+1) {
                head[i]=get(i+1);
            }
            dfs(i);
        }
    }
}

int hasEdge(int u, int v) {
    graph[u][v]=0;
    graph[v][u]=0;
    fill(all(seen),0);
    iota(all(head),0);
    s=0;
    dfs(0);
    if (s==n) {
        return 0;
    }
    graph[u][v]=1;
    graph[v][u]=1;
    return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...