結果
| 問題 |
No.1817 Reversed Edges
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2022-01-21 21:26:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,058 bytes |
| コンパイル時間 | 711 ms |
| コンパイル使用メモリ | 80,288 KB |
| 最終ジャッジ日時 | 2025-01-27 13:22:51 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 18 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned int;
#define rep(i,n) for(int i=0; i<(n); i++)
int N;
vector<vector<int>> E;
int main() {
cin >> N;
E.resize(N);
rep(i,N-1){
int u,v; cin >> u >> v; u--; v--;
E[u].push_back(v);
E[v].push_back(u);
}
vector<int> I = {0};
vector<int> P(N,-1);
rep(i,N){
int p = I[i];
for(int e : E[p]) if(P[p] != e){
P[e] = p;
I.push_back(e);
}
}
vector<int> path(N, 0);
for(int i=1; i<N; i++) if(P[i] < i) path[i]++; else path[i]--;
for(int i=1; i<N; i++) path[i] += path[P[i]];
int ans = 0;
for(int i=1; i<N; i++) if(P[i] > i) ans++;
rep(i,N) cout << (ans + path[i]) << "\n";
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia