Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3731 Accepted Submission(s): 1886
<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPGgzIGNsYXNzPQ=="panel_title" align="left">Input Input file contains multiple test cases.In each case there is natural number N (N<=10000) in the first line, followed by (N-1) lines with descriptions of computers. i-th line contains two natural numbers - number of computer, to which i-th computer is connected and length of cable used for connection. Total length of cable does not exceed 10^9. Numbers in lines of input are separated by a space.
#include#include #include #include using namespace std; const int INF = 999999999; struct Node { int v; int c; Node(){} Node(int V, int C) { v = V; c = C; } }; int n; std::vector v[10010]; int Fmax[10010];//first maxn int Smax[10010];//second maxn int visf[10010];//標記最大距離來自的電腦標號 int viss[10010];//標記次大距離來自的電腦標號 void init(int n) { for (int i=0; i<=n; i++) { v[i].clear(); } for (int i=0; i<=n; i++) { Fmax[i] = Smax[i] = -INF; } } void dfs0(int t, int fa) { Fmax[t] = 0; Smax[t] = 0; for (int i=0; i > n) { init(n ); int a, b; for (int i=2; i<=n; i++) { cin >> a >> b; v[i].push_back(Node(a,b)); v[a].push_back(Node(i,b)); } dfs0(1, -1); dfs1(1, -1, 0); for (int i=1; i<=n; i++) { cout << Fmax[i] <