結果

問題 No.1817 Reversed Edges
ユーザー 👑 NachiaNachia
提出日時 2022-01-21 21:28:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 10,412 KB
最終ジャッジ日時 2023-08-17 04:58:54
合計ジャッジ時間 3,469 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 55 ms
9,024 KB
testcase_08 AC 23 ms
6,064 KB
testcase_09 AC 46 ms
8,844 KB
testcase_10 AC 26 ms
6,520 KB
testcase_11 AC 33 ms
7,476 KB
testcase_12 AC 58 ms
10,004 KB
testcase_13 AC 60 ms
10,116 KB
testcase_14 AC 57 ms
10,212 KB
testcase_15 AC 57 ms
10,276 KB
testcase_16 AC 61 ms
10,000 KB
testcase_17 AC 62 ms
10,276 KB
testcase_18 AC 60 ms
10,000 KB
testcase_19 AC 63 ms
10,140 KB
testcase_20 AC 61 ms
10,000 KB
testcase_21 AC 57 ms
10,080 KB
testcase_22 AC 33 ms
10,344 KB
testcase_23 AC 34 ms
10,412 KB
testcase_24 AC 39 ms
9,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned int;
#define rep(i,n) for(int i=0; i<(n); i++)

int N;
vector<vector<int>> E;


int main() {
    cin >> N;
    E.resize(N);
    rep(i,N-1){
        int u,v; cin >> u >> v; u--; v--;
        E[u].push_back(v);
        E[v].push_back(u);
    }

    vector<int> I = {0};
    vector<int> P(N,-1);
    rep(i,N){
        int p = I[i];
        for(int e : E[p]) if(P[p] != e){
            P[e] = p;
            I.push_back(e);
        }
    }

    vector<int> path(N, 0);
    for(int i=1; i<N; i++) if(P[i] < i) path[i]++; else path[i]--;
    for(int i=1; i<N; i++) path[I[i]] += path[P[I[i]]];
    int ans = 0;
    for(int i=1; i<N; i++) if(P[i] > i) ans++;
    rep(i,N) cout << (ans + path[i]) << "\n";
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0