結果
問題 | No.1817 Reversed Edges |
ユーザー |
👑 ![]() |
提出日時 | 2022-01-21 21:28:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 1,064 bytes |
コンパイル時間 | 1,087 ms |
コンパイル使用メモリ | 80,164 KB |
最終ジャッジ日時 | 2025-01-27 13:24:04 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 23 |
ソースコード
#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[i]] += path[P[I[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;