結果
| 問題 |
No.1817 Reversed Edges
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-17 18:07:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 880 bytes |
| コンパイル時間 | 1,041 ms |
| コンパイル使用メモリ | 87,576 KB |
| 実行使用メモリ | 21,196 KB |
| 最終ジャッジ日時 | 2025-03-17 18:08:05 |
| 合計ジャッジ時間 | 7,334 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 WA * 19 |
ソースコード
#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];
bool vis[M];
int fa[M],dep[M],rev[M];
void dfs(int u,int from){
vis[u]=1;
rev[u]=0;
for(int v:e[u]){
if(v==from) continue;
if(u>v) rev[u]++;
fa[v]=u;
dep[v]=dep[u]+1;
dfs(v,u);
rev[u]+=rev[v];
}
}
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 fa=%d d=%d rev=%d\n",i,fa[i],dep[i],rev[i]);}
for(int u=1;u<=n;u++){
cout<<rev[1]+dep[u]-2*rev[u]<< endl;
}
return 0;
}