結果
問題 | No.277 根掘り葉掘り |
ユーザー | stack9996 |
提出日時 | 2015-09-05 00:11:45 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,067 bytes |
コンパイル時間 | 663 ms |
コンパイル使用メモリ | 76,076 KB |
実行使用メモリ | 18,404 KB |
最終ジャッジ日時 | 2023-09-26 07:28:49 |
合計ジャッジ時間 | 5,695 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
10,908 KB |
testcase_01 | AC | 4 ms
6,476 KB |
testcase_02 | AC | 4 ms
6,484 KB |
testcase_03 | AC | 5 ms
6,492 KB |
testcase_04 | AC | 4 ms
6,492 KB |
testcase_05 | AC | 4 ms
6,468 KB |
testcase_06 | AC | 4 ms
6,612 KB |
testcase_07 | AC | 4 ms
6,436 KB |
testcase_08 | AC | 4 ms
6,484 KB |
testcase_09 | TLE | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
ソースコード
#include <iostream> #include <cstdio> #include <numeric> #include <algorithm> #include <string> #include <vector> #include <functional> #include <cmath> #include <queue> #include <set> #define rep(i, a) REP(i, 0, a) #define REP(i, a, b) for(int i = a; i < b; ++i) typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> P; typedef std::pair<P, int> PP; struct edge{ int to, time, cost; }; const double esp = 1e-9; const int inf = (int)1e+9; struct Node{ int ans = inf; bool used = false; std::vector<Node*> v; }; int n; Node node[100001]; void updata(Node &n, int k){ if (n.used)return; n.used = true; n.ans = std::min(n.ans, k); int s = n.v.size(); rep(i, s)updata(*n.v[i], k + 1); } int main(){ std::cin >> n; rep(i, n - 1){ int x, y; std::cin >> x >> y; node[x - 1].v.push_back(&node[y - 1]); node[y - 1].v.push_back(&node[x - 1]); } updata(node[0], 0); rep(i, n){ rep(j, n)node[j].used = false; if (node[i].v.size() == 1)updata(node[i], 0); } rep(i, n)std::cout << node[i].ans << std::endl; return 0; }