Submission #900753

# Submission time Handle Problem Language Result Execution time Memory
900753 2024-01-09T02:02:26 Z nguyentunglam Meetings (JOI19_meetings) C++17
100 / 100
902 ms 1236 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 middle (int a, int b, int c) {
  del_edge(a, b);
  int x = Query(a, b, c);
  add_edge(a, x);
  add_edge(b, x);
  if (c != x) add_edge(c, x);
}

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;
//      cout << v << endl;
      if (Query(a, node, idx) != node) v = a;
      if (dd[v]) middle(node, v, idx);
      else centroid(v, idx);
      return;
    }
  }

  if (adj[node].size() % 2) {
    int v = adj[node].back();
    if (Query(v, node, idx) != node) {
      if (dd[v]) middle(node, v, idx);
      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++) if (adj[cur].empty()) {
    centroid(0, cur);
    for(int i = 0; i < n; 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:60:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   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 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 548 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 528 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 548 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 528 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 6 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 5 ms 560 KB Output is correct
30 Correct 5 ms 344 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 5 ms 344 KB Output is correct
33 Correct 6 ms 344 KB Output is correct
34 Correct 7 ms 596 KB Output is correct
35 Correct 7 ms 344 KB Output is correct
36 Correct 6 ms 564 KB Output is correct
37 Correct 11 ms 344 KB Output is correct
38 Correct 12 ms 344 KB Output is correct
39 Correct 10 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 980 KB Output is correct
2 Correct 353 ms 728 KB Output is correct
3 Correct 387 ms 964 KB Output is correct
4 Correct 334 ms 700 KB Output is correct
5 Correct 362 ms 1236 KB Output is correct
6 Correct 365 ms 688 KB Output is correct
7 Correct 345 ms 752 KB Output is correct
8 Correct 357 ms 600 KB Output is correct
9 Correct 336 ms 972 KB Output is correct
10 Correct 323 ms 736 KB Output is correct
11 Correct 360 ms 844 KB Output is correct
12 Correct 572 ms 736 KB Output is correct
13 Correct 424 ms 868 KB Output is correct
14 Correct 423 ms 772 KB Output is correct
15 Correct 401 ms 752 KB Output is correct
16 Correct 463 ms 760 KB Output is correct
17 Correct 359 ms 760 KB Output is correct
18 Correct 374 ms 764 KB Output is correct
19 Correct 412 ms 848 KB Output is correct
20 Correct 398 ms 1104 KB Output is correct
21 Correct 372 ms 848 KB Output is correct
22 Correct 400 ms 956 KB Output is correct
23 Correct 414 ms 848 KB Output is correct
24 Correct 384 ms 848 KB Output is correct
25 Correct 371 ms 852 KB Output is correct
26 Correct 361 ms 856 KB Output is correct
27 Correct 350 ms 720 KB Output is correct
28 Correct 392 ms 748 KB Output is correct
29 Correct 311 ms 968 KB Output is correct
30 Correct 316 ms 1236 KB Output is correct
31 Correct 345 ms 736 KB Output is correct
32 Correct 902 ms 1104 KB Output is correct
33 Correct 604 ms 808 KB Output is correct
34 Correct 5 ms 344 KB Output is correct
35 Correct 6 ms 344 KB Output is correct
36 Correct 6 ms 344 KB Output is correct
37 Correct 5 ms 344 KB Output is correct
38 Correct 5 ms 344 KB Output is correct
39 Correct 5 ms 344 KB Output is correct
40 Correct 6 ms 344 KB Output is correct
41 Correct 7 ms 576 KB Output is correct
42 Correct 7 ms 344 KB Output is correct
43 Correct 6 ms 344 KB Output is correct
44 Correct 11 ms 576 KB Output is correct
45 Correct 13 ms 344 KB Output is correct
46 Correct 9 ms 600 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 0 ms 344 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct