This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |