結果

問題 No.1817 Reversed Edges
ユーザー 沙耶花沙耶花
提出日時 2022-01-21 21:30:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 865 bytes
コンパイル時間 4,785 ms
コンパイル使用メモリ 261,824 KB
実行使用メモリ 16,840 KB
最終ジャッジ日時 2023-08-17 05:02:41
合計ジャッジ時間 9,777 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 200 ms
8,484 KB
testcase_08 AC 92 ms
5,680 KB
testcase_09 AC 190 ms
8,048 KB
testcase_10 AC 104 ms
5,972 KB
testcase_11 AC 135 ms
6,780 KB
testcase_12 AC 225 ms
9,152 KB
testcase_13 AC 225 ms
9,092 KB
testcase_14 AC 226 ms
9,176 KB
testcase_15 AC 227 ms
9,276 KB
testcase_16 AC 226 ms
9,244 KB
testcase_17 AC 226 ms
9,188 KB
testcase_18 AC 223 ms
9,152 KB
testcase_19 AC 222 ms
9,436 KB
testcase_20 AC 228 ms
9,276 KB
testcase_21 AC 221 ms
9,152 KB
testcase_22 AC 178 ms
9,280 KB
testcase_23 AC 181 ms
9,440 KB
testcase_24 AC 207 ms
16,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001
int n;
vector<vector<int>> E;
vector<int> ans;

int get(int cur,int p){
	int ret = 0;
	rep(i,E[cur].size()){
		int to = E[cur][i];
		if(to==p)continue;
		ret += get(to,cur);
		if(cur > to)ret++;
	}
	return ret;
}

int dfs(int cur,int p,int cv){
	ans[cur] = cv;

	rep(i,E[cur].size()){
		int to = E[cur][i];
		if(to==p)continue;
		if(cur > to){
			dfs(to,cur,cv - 1);
		}
		else{
			dfs(to,cur,cv+1);
		}
	}
	return 0;
}

int main(){
	
	cin>>n;
	E.resize(n);
	ans.resize(n,0);
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		u--;v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	
	int t = get(0,-1);
	
	dfs(0,-1,t);
	
	rep(i,n){
		cout<<ans[i]<<endl;
	}
	
	return 0;
}
0