結果

問題 No.1817 Reversed Edges
ユーザー ace_amuro
提出日時 2025-03-17 18:14:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 1,084 ms
コンパイル使用メモリ 86,392 KB
実行使用メモリ 18,500 KB
最終ジャッジ日時 2025-03-17 18:14:07
合計ジャッジ時間 6,249 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<ctime>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long LL;
const int M=2e5+10;
vector<int> e[M];
int dep[M],x[M];
int rev;
void dfs(int u,int from){
    for(int v:e[u]){
        if(v==from) continue;
        dep[v]=dep[u]+1;
        rev += (u>v);
        x[v] = x[u] + (u>v);
        dfs(v,u);
    }
}

int main(){
    int n;
    cin>>n;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    dfs(1,0);
    //for(int i=1;i<=n;i++){printf("i=%d d=%d x=%d\n",i,dep[i],x[i]);}
    for(int u=1;u<=n;u++){
        cout<<rev+dep[u]-2*x[u]<< endl;
    }
    return 0;
}
0