結果

問題 No.1817 Reversed Edges
ユーザー 沙耶花沙耶花
提出日時 2022-01-21 21:29:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 856 bytes
コンパイル時間 4,542 ms
コンパイル使用メモリ 263,816 KB
実行使用メモリ 821,632 KB
最終ジャッジ日時 2024-05-04 11:58:20
合計ジャッジ時間 7,628 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 MLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int dfs(int, int, int)':
main.cpp:38:1: warning: no return statement in function returning non-void [-Wreturn-type]
   38 | }
      | ^

ソースコード

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);
		}
	}
	
}

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