Submission #1043758

# Submission time Handle Problem Language Result Execution time Memory
1043758 2024-08-04T16:30:27 Z abczz Meetings (JOI19_meetings) C++17
0 / 100
559 ms 1104 KB
#include "meetings.h"
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <array>
#define ll long long

using namespace std;

bool C[2000];
ll sz[2000], tot, node_cnt;
unordered_map <ll, ll> adj[2000];

void add_edge(ll u, ll v) {
  adj[u][v] = adj[v][u] = 1;
}
void del_edge(ll u, ll v) {
  adj[u].erase(v);
  adj[v].erase(u);
}
void ins(ll u, ll v, ll x) {
  del_edge(u, v);
  add_edge(u, x);
  add_edge(x, v);
}
ll find_centroid(ll u, ll p, ll w) {
  sz[u] = 1;
  ll mx = -1, res = -1;
  for (auto [v, x] : adj[u]) {
    if (!C[v] && v != p) {
      res = max(res, find_centroid(v, u, w));
      sz[u] += sz[v];
      mx = max(mx, sz[v]);
    }
  }
  mx = max(mx, w-sz[u]);
  if (mx <= w/2) return u;
  else return res;
}

void dfs_sz(ll u, ll p) {
  sz[u] = 1;
  for (auto [v, x] : adj[u]) {
    if (!C[v] && v != p) {
      dfs_sz(v, u);
      sz[u] += sz[v];
    }
  }
}

void solve(ll u, ll w) {
  ll c = find_centroid(u, -1, w);
  dfs_sz(c, -1);
  C[c] = 1;
  vector <array<ll, 2>> V;
  for (auto [v, x] : adj[c]) {
    if (!C[v]) {
      V.push_back({sz[v], v});
    }
  }
  sort(V.begin(), V.end());
  while (!V.empty()) {
    if (V.size() > 1) {
      auto [x, a] = V.back();
      V.pop_back();
      auto [y, b] = V.back();
      V.pop_back();
      ll z = Query(a, b, tot);
      if (z == a) {
        solve(a, sz[a]);
        return;
      }
      else if (z == b) {
        solve(b, sz[b]);
        return;
      }
      else if (z == tot) {
        ll tmp = Query(a, tot, c);
        if (tmp == tot) ins(a, c, tot);
        else ins(b, c, tot);
        return;
      }
    }
    else {
      auto [x, a] = V.back();
      V.pop_back();
      ll z = Query(a, c, tot);
      if (z == tot) ins(a, c, tot);
      else if (z == a) solve(a, sz[a]);
      else add_edge(c, tot);
      return;
    }
  }
  add_edge(c, tot);
}
void Solve(int N) {
  for (int i=0; i<N; ++i) {
    adj[i].clear();
  }
  ll x = Query(0, 1, 2);
  node_cnt = 1;
  for (int i=0; i<=2; ++i) {
    if (i == x) continue;
    add_edge(i, x);
    ++node_cnt;
  }
  for (int i=3; i<N; ++i) {
    if (i == x) continue;
    tot = i;
    for (int j=0; j<N; ++j) {
      C[j] = 0;
    }
    solve(0, node_cnt);
    ++node_cnt;
  }
  for (int i=0; i<N; ++i) {
    for (auto [v, x] : adj[i]) {
      if (i > v) continue;
      Bridge(i, v);
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Incorrect 0 ms 600 KB Wrong Answer [4]
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Incorrect 0 ms 600 KB Wrong Answer [4]
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Incorrect 0 ms 600 KB Wrong Answer [4]
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 559 ms 1104 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -