結果
| 問題 |
No.277 根掘り葉掘り
|
| コンテスト | |
| ユーザー |
mayoko_
|
| 提出日時 | 2015-09-04 22:36:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,256 bytes |
| コンパイル時間 | 727 ms |
| コンパイル使用メモリ | 85,712 KB |
| 実行使用メモリ | 17,408 KB |
| 最終ジャッジ日時 | 2024-07-19 01:00:40 |
| 合計ジャッジ時間 | 3,480 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 WA * 8 |
ソースコード
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
const int MAXN = 100010;
vector<int> G[MAXN];
int dp[MAXN], d[MAXN];
void dfs(int v, int p, int depth) {
d[v] = depth;
dp[v] = MAXN;
bool leaf = true;
for (int ch : G[v]) {
if (ch == p) continue;
leaf = false;
dfs(ch, v, depth+1);
dp[v] = min(dp[v], dp[ch]+1);
}
if (leaf) dp[v] = 0;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
for (int i = 0; i < N-1; i++) {
int x, y;
cin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(1, 0, 0);
for (int i = 1; i <= N; i++) {
cout << min(d[i], dp[i]) << endl;
}
return 0;
}
mayoko_