結果
問題 | No.277 根掘り葉掘り |
ユーザー | naimonon77 |
提出日時 | 2016-02-24 13:33:22 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,543 bytes |
コンパイル時間 | 1,364 ms |
コンパイル使用メモリ | 166,372 KB |
実行使用メモリ | 6,208 KB |
最終ジャッジ日時 | 2023-10-23 19:35:15 |
合計ジャッジ時間 | 4,033 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
6,208 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 2 ms
6,204 KB |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:72:13: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘int’ [-Wformat=] 72 | scanf("%d%d",x,y); | ~^ ~ | | | | int* int main.cpp:72:15: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘int’ [-Wformat=] 72 | scanf("%d%d",x,y); | ~^ ~ | | | | int* int main.cpp:72:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 72 | scanf("%d%d",x,y); | ~~~~~^~~~~~~~~~~~ main.cpp:72:10: warning: ‘y’ may be used uninitialized [-Wmaybe-uninitialized] 72 | scanf("%d%d",x,y); | ~~~~~^~~~~~~~~~~~ main.cpp:71:11: note: ‘y’ declared here 71 | int x,y; | ^ main.cpp:72:10: warning: ‘x’ may be used uninitialized [-Wmaybe-uninitialized] 72 | scanf("%d%d",x,y); | ~~~~~^~~~~~~~~~~~ main.cpp:71:9: note: ‘x’ declared here 71 | int x,y; | ^
ソースコード
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #ifdef __unix__ #include <bits/stdc++.h> #else #include "bits\stdc++.h" #endif #include <vector> #include <set> #include <string> #include <queue> #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define MAX 100005 int N; vector<int> connect[MAX]; int ans[MAX] = {0,0}; bool isleaf[MAX] = {0}; int INF = 1 << 30; void seek_depth() { int i; bool visited[MAX]={0}; queue<int> qu; qu.push(1); visited[1] = true; while( not qu.empty() ) { int now = qu.front(); qu.pop(); rep(i,connect[now].size()) { int next = connect[now][i]; if( not visited[next] ) { visited[next] = true; ans[next] = ans[now]+1; qu.push(next); } } } } void seek_L(int leaf) { int i; queue<int> qu; ans[leaf] = 0; qu.push(leaf); while( not qu.empty() ) { int now = qu.front(); qu.pop(); rep(i,connect[now].size()) { int next = connect[now][i]; if(ans[next] > ans[now]+1) { ans[next] = ans[now]+1; qu.push(next); } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int i,j,k; cin >> N; rep(i,N-1) { int x,y; scanf("%d%d",x,y); connect[x].push_back(y); connect[y].push_back(x); } seek_depth(); for(i=1;i<N+1;i++) { if(connect[i].size() == 1) seek_L(i); } for(i=1;i<N+1;i++) { cout << ans[i] << endl; } return 0; }