Submission #76618

# Submission time Handle Problem Language Result Execution time Memory
76618 2018-09-15T08:33:03 Z Bodo171 Dreaming (IOI13_dreaming) C++14
0 / 100
74 ms 10964 KB
#include "dreaming.h"
#include <iostream>
#include <vector>
using namespace std;
const int nmax=100005;
vector< pair<int,int> > v[nmax];
vector<int> centr;
int d[nmax],viz[nmax],rep[nmax],dist[nmax];
int far,root,n,nr,i,x,mx,mn,ans;
void dfs(int x)
{
    int nod=0;
    viz[x]=1;rep[++nr]=x;
    for(int i=0;i<v[x].size();i++)
    {
        nod=v[x][i].first;
        if(!viz[nod])
        {
            d[nod]=d[x]+v[x][i].second;
            dfs(nod);
        }
    }
}
void get_diam()
{
    far=root;nr=0;
    dfs(root);
    for(i=1;i<=nr;i++)
    {
        x=rep[i];
        if(d[x]>d[far])
            far=x;
        viz[x]=0;
    }
    nr=0;d[far]=0;
    dfs(far);mx=0;
    for(i=1;i<=nr;i++)
    {
        x=rep[i];
        if(d[x]>d[far])
            far=x;
        dist[x]=max(dist[x],d[x]);
        viz[x]=0;
    }
    d[far]=0;
    dfs(far);
    for(i=1;i<=nr;i++)
    {
        x=rep[i];
        dist[x]=max(dist[x],d[x]);
    }
    mn=(1<<30);
    for(i=1;i<=nr;i++)
    {
        x=rep[i];
        if(dist[x]<mn)
            mn=dist[x];
    }
    centr.push_back(mn);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n=N;
    for(i=0;i<M;i++)
    {
        v[A[i]].push_back({B[i],T[i]});
        v[B[i]].push_back({A[i],T[i]});
    }
    for(root=1;root<=n;root++)
        if(!viz[root])
            get_diam();
    for(i=0;i<centr.size();i++)
    {
        ans+=centr[i];
        if(i+1<centr.size())
            ans+=L;
    }
    return ans;
}

Compilation message

dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:71:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<centr.size();i++)
             ~^~~~~~~~~~~~~
dreaming.cpp:74:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i+1<centr.size())
            ~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 10964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 10964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 10964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 6520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 10964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 10964 KB Output isn't correct
2 Halted 0 ms 0 KB -