Saratov State University :: Online Contester


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

::Poll
Are you registered on Codeforces?
Yes
No
What 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;
}


see sub-tree reply to that message


::Login
Forgot password?

::News
22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553).
22.10.12 - After the start of the contest the statements in PDF will be available by the link.
23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

Server time: 2017-11-23 06:36:12Online Contester Team © 2002 - 2016. All rights reserved.