結果
問題 | No.277 根掘り葉掘り |
ユーザー | hirokazu1020 |
提出日時 | 2015-09-04 23:21:51 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 225 ms / 3,000 ms |
コード長 | 1,025 bytes |
コンパイル時間 | 2,086 ms |
コンパイル使用メモリ | 99,280 KB |
実行使用メモリ | 9,664 KB |
最終ジャッジ日時 | 2023-09-26 06:43:37 |
合計ジャッジ時間 | 4,505 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,744 KB |
testcase_01 | AC | 3 ms
5,800 KB |
testcase_02 | AC | 4 ms
5,676 KB |
testcase_03 | AC | 3 ms
5,804 KB |
testcase_04 | AC | 4 ms
5,804 KB |
testcase_05 | AC | 4 ms
5,752 KB |
testcase_06 | AC | 4 ms
5,668 KB |
testcase_07 | AC | 4 ms
5,660 KB |
testcase_08 | AC | 4 ms
5,672 KB |
testcase_09 | AC | 216 ms
9,180 KB |
testcase_10 | AC | 193 ms
9,604 KB |
testcase_11 | AC | 214 ms
9,388 KB |
testcase_12 | AC | 214 ms
9,400 KB |
testcase_13 | AC | 225 ms
9,576 KB |
testcase_14 | AC | 214 ms
9,472 KB |
testcase_15 | AC | 213 ms
9,484 KB |
testcase_16 | AC | 211 ms
9,416 KB |
testcase_17 | AC | 213 ms
9,452 KB |
testcase_18 | AC | 213 ms
9,528 KB |
testcase_19 | AC | 214 ms
9,664 KB |
ソースコード
#include<sstream> #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<string> #include<vector> #include<set> #include<map> #include<queue> #include<numeric> #include<functional> #include<algorithm> #include<bitset> #include<tuple> #include<unordered_set> #include<random> using namespace std; #define INF (1<<29) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() #define uniq(v) v.erase(unique(all(v)),v.end()) #define indexOf(v,x) (find(all(v),x)-v.begin()) int ans[100000]; int n; vector<int> edge[100000]; int main() { cin>>n; rep(u,n-1){ int x,y; cin>>x>>y; x--;y--; edge[x].push_back(y); edge[y].push_back(x); } fill_n(ans,n,-1); queue<int> q; ans[0]=0; q.push(0); rep(i,n)if(edge[i].size()==1){ q.push(i); ans[i]=0; } while(!q.empty()){ int u=q.front();q.pop(); rep(i,edge[u].size()){ int v=edge[u][i]; if(ans[v]==-1){ ans[v]=ans[u]+1; q.push(v); } } } rep(i,n)cout<<ans[i]<<endl; return 0; }