結果
問題 | No.277 根掘り葉掘り |
ユーザー |
![]() |
提出日時 | 2015-09-04 22:37:04 |
言語 | C++11 (gcc 8.5.0) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,720 bytes |
コンパイル時間 | 1,418 ms |
使用メモリ | 33,084 KB |
最終ジャッジ日時 | 2023-02-17 02:29:27 |
合計ジャッジ時間 | 10,295 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
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 dfs(int, int)’: main.cpp:52:15: warning: control reaches end of non-void function [-Wreturn-type] map<int,int> s; ^
ソースコード
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cctype> #include<cstdlib> #include<algorithm> #include<bitset> #include<vector> #include<list> #include<deque> #include<queue> #include<map> #include<set> #include<stack> #include<cmath> #include<sstream> #include<fstream> #include<iomanip> #include<ctime> #include<complex> #include<functional> #include<climits> #include<cassert> #include<iterator> using namespace std; #define MAX 100002 int n; vector<int> v[MAX]; bool use[MAX]; int ans[MAX]; int dep[MAX]; inline void dfs2(int a){ use[a] = true; dep[a] = INT_MAX; int countt = 0; for (int i = 0; i < v[a].size(); i++){ if (use[v[a][i]] == false){ dfs2(v[a][i]); dep[a] = min(dep[a], dep[v[a][i]] + 1); countt++; } } if (countt== 0){ dep[a] = 0; } return; } inline int dfs(int a, int b){ use[a] = false; ans[a] = INT_MAX; map<int,int> s; s.clear(); int countt = 0; for (int i = 0; i < v[a].size(); i++){ if (use[v[a][i]] == false){ continue; } countt++; s[dep[v[a][i]]+1]++; } if (countt == 0){ ans[a] = 0; return 0; } s[b]++; map<int, int>::iterator ite; ite = s.begin(); ans[a] = (*ite).first; for (int i = 0; i < v[a].size(); i++){ if (use[v[a][i]] == false){ continue; } int val = dep[v[a][i]]+1; s[val]--; if (s[val] == 0){ s.erase(val); } ite = s.begin(); dfs(v[a][i], (*ite).first+1); s[val]++; } } int main(){ scanf("%d", &n); for (int i = 1; i < n; i++){ int a, b; scanf("%d%d", &a, &b); a--; b--; v[a].push_back(b); v[b].push_back(a); } for (int i = 0; i < n; i++){ ans[i] = INT_MAX; } dfs2(0); dfs(0, 0); for (int i = 0; i < n; i++){ printf("%d\n", ans[i]); } return 0; }