이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#include<bits/stdc++.h>
using namespace std;
struct Runner {
static 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;
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);
}
}
};
Runner runner;
void Solve(int N) {
Runner newRunner;
swap(runner, newRunner);
runner.Solve(N);
}
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In member function 'void Runner::del_edge(int, int)':
meetings.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i = 0; i < adj[u].size(); i++) if (adj[u][i] == v) {
| ~~^~~~~~~~~~~~~~~
meetings.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0; i < adj[v].size(); i++) if (adj[v][i] == u) {
| ~~^~~~~~~~~~~~~~~
meetings.cpp: In member function 'void Runner::centroid(int, int)':
meetings.cpp:61:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i = 0; i + 1 < adj[node].size(); i += 2) {
| ~~~~~~^~~~~~~~~~~~~~~~~~
meetings.cpp: In function 'void Solve(int)':
meetings.cpp:5:8: warning: 'newRunner.Runner::n' is used uninitialized in this function [-Wuninitialized]
5 | struct Runner {
| ^~~~~~
# | 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... |