結果
| 問題 |
No.277 根掘り葉掘り
|
| コンテスト | |
| ユーザー |
stack9996
|
| 提出日時 | 2015-09-05 00:11:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,067 bytes |
| コンパイル時間 | 602 ms |
| コンパイル使用メモリ | 76,604 KB |
| 実行使用メモリ | 11,776 KB |
| 最終ジャッジ日時 | 2024-07-19 02:36:55 |
| 合計ジャッジ時間 | 5,400 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 7 TLE * 1 -- * 10 |
ソースコード
#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;
}
stack9996