### Saratov State University :: Online Contester

::Go
- home
- news
- register
 - update personal info
 - problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- projects

 ::Poll Are you registered on Codeforces?YesNoWhat is it???[results]

::webboard

 Presentation Error On Test 1???
Author: osoulim
ID: 058602
Problem: 149
Contest: 0
Date: 2014-11-02 07:26:21

My Code Gets Presentation Error On Test 1, But Removing "return 0;" Fixed It, WHAT THE WHAT????

#include<bits/stdc++.h>

using namespace std;

const int maxn = 1000 * 100 + 10;
vector <pair <int, int > > g[maxn];
int mark[maxn];
int dis[3][maxn];
int n, s;

void input()
{
cin>>n;
for(int i=1; i<n; i++)
{
int a, b;
cin>>a>>b;
a--;
g[i].push_back(make_pair(a, b));
g[a].push_back(make_pair(i, b));

}
}

void dfs(int v, int t)
{
mark[v] = 1;
for(int i=0; i<g[v].size(); i++)
{
int u = g[v][i].first;
int w = g[v][i].second;
if(!mark[u])
{
dis[t][u] = dis[t][v] + w;
dfs(u, t);
}
}
}

int find_max(int t)
{
int u = 0, maxu = 0;
for(int i=0; i<n; i++)
if(dis[t][i] > maxu)
maxu = dis[t][i], u = i;
return u;
}

int main()
{
input();
dfs(0, 0);

memset(mark, 0, sizeof mark);
s = find_max(0);
dfs(s, 1);

memset(mark, 0, sizeof mark);
s = find_max(1);
dfs(s, 2);

for(int i=0; i<n; i++)
cout<<(int)(max(dis[1][i], dis[2][i]))<<endl;
//return 0;
}