結果
| 問題 | 
                            No.277 根掘り葉掘り
                             | 
                    
| コンテスト | |
| ユーザー | 
                             nopperi
                         | 
                    
| 提出日時 | 2015-09-05 06:57:07 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 585 bytes | 
| コンパイル時間 | 441 ms | 
| コンパイル使用メモリ | 61,316 KB | 
| 実行使用メモリ | 8,128 KB | 
| 最終ジャッジ日時 | 2024-07-19 03:45:09 | 
| 合計ジャッジ時間 | 3,671 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 5 WA * 13 | 
ソースコード
#include <iostream>
#include <vector>
using namespace std;
vector <int> node[100001];
int cost[100001];
int dfs(int n) {
    if (0 == node[n].size()) {
        return 0;
    }
    int m = 1000000;
    for (int i = 0; i < node[n].size(); i++) {
        m = min(m, 1+dfs(node[n][i]));
    }
    return m;
}
int main(void) {
    int n, x, y;
    cin >> n;
    for (int i = 0; i < n-1; i++) {
        cin >> x >> y;
        node[x].push_back(y);
        cost[y] = 1 + cost[x];
    }
    for (int i = 1; i <= n; i++) {
        cout << min(dfs(i), cost[i]) << endl;
    }
    return 0;
}
            
            
            
        
            
nopperi