제출 #50160

#제출 시각아이디문제언어결과실행 시간메모리
50160Just_Solve_The_ProblemGame (IOI14_game)C++11
42 / 100
1065 ms3028 KiB
#include <bits/stdc++.h>
#include "game.h"

using namespace std;

#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()

const int N = 1500 + 7;

int n;
vector < int > gr[N];

void initialize(int nn) {
  n = nn;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      gr[i].pb(j);
      gr[j].pb(i);
    }
  }
}

bool check() {
  queue < int > q;
  q.push(0);
  vector < int > used(n);
  used[0] = 1;
  int c = 1;
  while(!q.empty()) {
    int v = q.front();
    q.pop();
    for (int to : gr[v]) {
      if (!used[to]) {
        q.push(to);
        used[to] = 1;
        c++;
      }
    }
  }
  return c == n;
}

int hasEdge(int u, int v) {
  gr[u].erase(find(all(gr[u]), v));
  gr[v].erase(find(all(gr[v]), u));
  if (!check()) {
    gr[u].pb(v);
    gr[v].pb(u);
    return 1;
  }
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...