# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
857956 | Trisanu_Das | Village (BOI20_village) | C++17 | 76 ms | 18256 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, ans[100005], resx;
vector<ll> adj[100005];
pair<ll, ll> S(ll x, ll y){
vector<pair<ll, ll> > a;
a.clear();
pair<ll, ll> b;
for(int i = 0; i < adj[x].size(); i++){
if(adj[x][i] != y){
b = S(adj[x][i], x);
if(b.first == b.second) a.push_back(b);
}
}
if(a.size() == 0){
if(y == 0){
ans[b.second] = x;
ans[x] = b.first;
resx += 2;
return {0, 0};
}else return {x, x};
}else{
a.push_back({x, x});
ll m = a.size() - 2;
for(int i=0;i<=m;i++){
ans[a[i].first] = a[i + 1].first;
resx += 2;
}
ans[x] = a[0].first;
return {x, a[m].first};
}
}
int main(){
cin >> n;
for(int i=1;i<n;i++){
ll u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
S(1, 0);
cout << resx << ' ' << 0 << '\n';
for(int i = 1; i <= n; i++) cout << ans[i] << ' ';
cout << '\n';
for(int i = 1; i <= n; i++) cout << i << ' ';
cout << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |