Submission #900745

# Submission time Handle Problem Language Result Execution time Memory
900745 2024-01-09T01:32:20 Z nguyentunglam Meetings (JOI19_meetings) C++17
0 / 100
358 ms 752 KB
#include "meetings.h"
#include<bits/stdc++.h>
using namespace std;

const int N = 2e3 + 10;

bool dd[N];

int sz[N];

vector<int> adj[N];

int n;

void add_edge (int u, int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}

void del_edge (int u, int v) {
  for(int i = 0; i < adj[u].size(); i++) if (adj[u][i] == v) {
    adj[u].erase(adj[u].begin() + i);
  }
  for(int i = 0; i < adj[v].size(); i++) if (adj[v][i] == u) {
    adj[v].erase(adj[v].begin() + i);
  }
}

int calc (int u, int p) {
  sz[u] = 1;
  for(int &v : adj[u]) if (v != p && !dd[v]) sz[u] += calc(v, u);
  return sz[u];
}

int getcentr (int u, int p, int cnt) {
  for(int &v : adj[u]) if (v != p && !dd[v] && sz[v] * 2 > cnt)
    return getcentr(v, u, cnt);
  return u;
}

void centroid (int u, int idx) {
  int node = getcentr(u, u, calc(u, u));

  dd[node] = 1;

  sort(adj[node].begin(), adj[node].end(), [&] (const int &x, const int &y) {
       return sz[x] > sz[y];
       });

//  cout << node << endl;

  for(int i = 0; i + 1 < adj[node].size(); i += 2) {
    int a = adj[node][i];
    int b = adj[node][i + 1];
    if (Query(a, b, idx) != node) {
      int v = b;
      if (Query(a, node, idx) != node) v = a;
      if (dd[v]) {
        del_edge(v, node);
        add_edge(idx, v);
        add_edge(idx, node);
      }
      else centroid(v, idx);
      return;
    }
  }

  if (adj[node].size() % 2) {
    int v = adj[node].back();
    if (Query(v, node, idx) != node) {
      if (dd[v]) {
        del_edge(v, node);
        del_edge(idx, v);
        add_edge(idx, node);
      }
      else centroid(v, idx);
      return;
    }
  }

  add_edge(node, idx);
}

void Solve(int N) {
  n = N;
  for(int i = 0; i < n; i++) adj[i].clear(), dd[i] = 0;

  add_edge(0, 1);

  for(int cur = 2; cur < n; cur++) {
    centroid(0, cur);
    for(int i = 0; i < cur; i++) dd[i] = 0;
  }

//  for(int i = 0; i < n; i++) for(int &j : adj[i]) if (i < j) {
//    cout << i << " " << j << endl;
//  }

  for(int i = 0; i < n; i++) for(int &j : adj[i]) if (i < j) {
    Bridge(i, j);
  }
}

Compilation message

meetings.cpp: In function 'void del_edge(int, int)':
meetings.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for(int i = 0; i < adj[u].size(); i++) if (adj[u][i] == v) {
      |                  ~~^~~~~~~~~~~~~~~
meetings.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int i = 0; i < adj[v].size(); i++) if (adj[v][i] == u) {
      |                  ~~^~~~~~~~~~~~~~~
meetings.cpp: In function 'void centroid(int, int)':
meetings.cpp:52:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(int i = 0; i + 1 < adj[node].size(); i += 2) {
      |                  ~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 358 ms 752 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -