結果
| 問題 |
No.1817 Reversed Edges
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2022-01-21 21:29:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 856 bytes |
| コンパイル時間 | 4,415 ms |
| コンパイル使用メモリ | 254,316 KB |
| 最終ジャッジ日時 | 2025-01-27 13:25:09 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 2 TLE * 1 MLE * 20 |
コンパイルメッセージ
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 | }
| ^
ソースコード
#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;
}
沙耶花