Submission #93156

# Submission time Handle Problem Language Result Execution time Memory
93156 2019-01-06T16:04:10 Z Vardanyan Hard route (IZhO17_road) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 5005
vector<int> g[N];
int dist[N];
void dfs(int v,int p = -1){
    for(int i = 0;i<g[v].size();i++){
        int to = g[v][i];
        if(to == p) continue;
        dfs(to,v);
        dist[v] = max(dist[v],dist[to]+1);
    }
}
unordered_map<long long,int> H;
long long mx = 0;
int n;
void calc(int v,int hard = 0,int d = 0,int p = -1){
    if((g[v].size() == 1 && d+1 == n)){
        hard = min(hard,dist[v]);
    }
   if(g[v].size() == 1 && p!=-1){
        long long now = (long long)hard*(long long)d;
        H[now]++;
        mx = max(mx,now);
   }
   int mx1,mx2;
   mx1 = mx2 = 0;
   for(int i = 0;i<g[v].size();i++){
        int to = g[v][i];
        if(to == p) continue;
        if(dist[to]+1>mx1){
            mx1 = dist[to]+1;
        }
        else if(dist[to]+1>mx2){
            mx2 = dist[to]+1;
        }
   }
    for(int i = 0;i<g[v].size();i++){
        int to = g[v][i];
        if(to == p) continue;
        int h = -1;
        if(dist[to]+1 == mx1) h = mx2;
        else h = mx1;/*
        if(dist[v]>hard){
            for(int j = 0;j<g[v].size();j++){
                int too = g[v][j];
                if(too!=to && too!=p){
                    if(h == -1 || dist[too]+1>h) h = dist[too]+1;
                }
            }
        }*/
        int hardd = hard;
        if(h!=-1){
            hardd = max(hardd,h);
        }
        calc(to,hardd,d+1,v);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(int i = 1;i<=n-1;i++){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i = 1;i<=n;i++){
        if(g[i].size() == 1){
            memset(dist,0,sizeof dist);
            dfs(i);
            calc(i);
        }
    }
    //cout<<H[mx]<<endl;
    cout<<mx<<" "<<H[mx]/2<<endl;
	return 0;
}

Compilation message

road.cpp:4:1: error: expected ',' or ';' before 'vector'
 vector<int> g[N];
 ^~~~~~
road.cpp: In function 'void dfs(int, int)':
road.cpp:7:21: error: 'g' was not declared in this scope
     for(int i = 0;i<g[v].size();i++){
                     ^
road.cpp: In function 'void calc(int, int, int, int)':
road.cpp:18:9: error: 'g' was not declared in this scope
     if((g[v].size() == 1 && d+1 == n)){
         ^
road.cpp:21:7: error: 'g' was not declared in this scope
    if(g[v].size() == 1 && p!=-1){
       ^
road.cpp:28:20: error: 'g' was not declared in this scope
    for(int i = 0;i<g[v].size();i++){
                    ^
road.cpp:38:21: error: 'g' was not declared in this scope
     for(int i = 0;i<g[v].size();i++){
                     ^
road.cpp: In function 'int main()':
road.cpp:65:9: error: 'g' was not declared in this scope
         g[x].push_back(y);
         ^
road.cpp:69:12: error: 'g' was not declared in this scope
         if(g[i].size() == 1){
            ^