QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#760242#9713. Kill the treethangthangWA 83ms26304kbC++201.4kb2024-11-18 15:48:272024-11-18 15:48:46

Judging History

This is the latest submission verdict.

  • [2024-11-18 15:48:46]
  • Judged
  • Verdict: WA
  • Time: 83ms
  • Memory: 26304kb
  • [2024-11-18 15:48:27]
  • 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){
        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;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 83ms
memory: 26304kb

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:

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

result:

wrong answer 1st numbers differ - expected: '1', found: '134385'