QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#125520 | #6740. Function | rniya | WA | 1ms | 3440kb | C++17 | 2.6kb | 2023-07-16 19:55:36 | 2023-07-16 19:55:38 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
using namespace std;
typedef long long ll;
#define all(x) begin(x), end(x)
constexpr int INF = (1 << 30) - 1;
constexpr long long IINF = (1LL << 60) - 1;
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
template <class T> istream& operator>>(istream& is, vector<T>& v) {
for (auto& x : v) is >> x;
return is;
}
template <class T> ostream& operator<<(ostream& os, const vector<T>& v) {
auto sep = "";
for (const auto& x : v) os << exchange(sep, " ") << x;
return os;
}
template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); }
template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); }
template <class T> void mkuni(vector<T>& v) {
sort(begin(v), end(v));
v.erase(unique(begin(v), end(v)), end(v));
}
template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); }
const int MAX = 10;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<vector<int>> G(n);
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
x--, y--;
G[x].emplace_back(y);
G[y].emplace_back(x);
}
vector<int> sub(n), alive(n, true);
auto dfs_sz = [&](auto self, int v, int p) -> int {
sub[v] = 1;
for (int& u : G[v]) {
if (u == p or not alive[u]) continue;
sub[v] += self(self, u, v);
}
return sub[v];
};
auto dfs_search_centroid = [&](auto self, int v, int p, int mid) -> int {
for (int& u : G[v]) {
if (u == p or not alive[u]) continue;
if (sub[u] > mid) return self(self, u, v, mid);
}
return v;
};
vector<vector<int>> ans(MAX);
auto solve = [&](auto self, int r, int d) -> void {
assert(d < 10);
int c = dfs_search_centroid(dfs_search_centroid, r, -1, dfs_sz(dfs_sz, r, -1) / 2);
ans[d].emplace_back(c);
alive[c] = false;
for (int& ch : G[c]) {
if (not alive[ch]) continue;
self(self, ch, d + 1);
}
};
solve(solve, 0, 0);
while (ans.back().empty()) ans.pop_back();
reverse(begin(ans), end(ans));
cout << ans.size() << '\n';
for (auto& v : ans) {
cout << v.size();
for (int& x : v) cout << ' ' << x + 1;
cout << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3440kb
input:
1
output:
1 1 1
result:
wrong answer Output contains longer sequence [length = 3], but answer contains 1 elements