QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#760252#9713. Kill the treethangthangWA 97ms26216kbC++201.5kb2024-11-18 15:50:222024-11-18 15:50:23

Judging History

This is the latest submission verdict.

  • [2024-11-18 15:50:23]
  • Judged
  • Verdict: WA
  • Time: 97ms
  • Memory: 26216kb
  • [2024-11-18 15:50:22]
  • Submitted

answer

// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

int n, sz[N], cen[N], par[N];
vector <int> adj[N];
pair <int, int> ans[N];

void dfs(int u, int p){
    sz[u] = 1; par[u] = p;
    pair <int, int> Max = {1, u};
    for (int v : adj[u]) if (v != p){
        dfs(v, u);
        sz[u] += sz[v];
        Max = max(Max, {sz[v], cen[v]});
    }

    cen[u] = Max.se;
    while (sz[cen[u]] * 2 < sz[u]) cen[u] = par[cen[u]];
    ans[u].fi = cen[u];
    if (sz[cen[u]] * 2 == sz[u]) ans[u].se = par[cen[u]];
}

void solve(){
    cin >> n;
    for (int i = 1, u, v; i < n; ++ i){
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(1, 0);
    for (int i = 1; i <= n; ++ i){
        if (ans[i].se < ans[i].fi) swap(ans[i].se, ans[i].fi);
        if (ans[i].fi) cout << ans[i].fi << ' ';
        if (ans[i].se) cout << ans[i].se;
        cout << endl;
    }
}

int main(){
    if (fopen("pqh.inp", "r")){
        freopen("pqh.inp", "r", stdin);
        freopen("pqh.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}


详细

Test #1:

score: 0
Wrong Answer
time: 97ms
memory: 26216kb

input:

200000
42924 18271
60536 154257
107175 95680
196335 71607
158051 155259
110869 30974
143595 43516
4228 138046
26249 183847
123888 199873
15009 25362
166527 175160
15257 67159
124779 199363
148904 54047
5988 18123
58281 40739
44562 143880
72819 132492
137782 29662
130741 78276
55073 93292
82700 18328...

output:

1 134385
45886 143670
106649 126220
44121 108393
5226 95313
116080 147311
141180
147983
7428 74120
161963
3879
178499
162544 171549
144413
127262
133093 188325
171802
43558
28179
125217 140604
186651
45633 176397
26425
3745 26982
30063
128965
19661 148036
141733
115691
3491
8560 36057
12536 195673
1...

result:

wrong answer 251712th numbers differ - expected: '59926', found: '167799'