結果
問題 |
No.277 根掘り葉掘り
|
ユーザー |
![]() |
提出日時 | 2015-09-05 02:42:33 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 203 ms / 3,000 ms |
コード長 | 801 bytes |
コンパイル時間 | 638 ms |
コンパイル使用メモリ | 75,188 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-07-19 03:35:45 |
合計ジャッジ時間 | 3,821 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <iostream> #include <vector> #include <queue> #include <map> using namespace std; typedef vector <int> VI; typedef vector <VI> VVI; typedef pair <int,int> PII; #define range(i,a,b) for(int i=(a); i < (b); i++) #define rep(i,n) range(i,0,n) #define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++) int main(){ int N,x,y,d=0,h; PII tmp; VVI e; VI S; queue <PII> n; cin >> N; e = VVI(N); S = VI(N,N); rep(i,N-1){ cin >> x >> y; x--; y--; e[x].push_back(y); e[y].push_back(x); } n.push(PII(0,0)); rep(i,N) if(e[i].size() == 1) n.push(PII(0,i)); while(!n.empty()){ tmp = n.front(); d = tmp.first; h = tmp.second; n.pop(); if(d >= S[h]) continue; S[h] = d; each(nxt, e[h]) n.push(PII(d+1,*nxt)); } rep(i,N) cout << S[i] << endl; return 0; }