답안 #76620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76620 2018-09-15T08:46:18 Z Bodo171 꿈 (IOI13_dreaming) C++14
0 / 100
89 ms 10876 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,maxdiam;
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]);
        if(d[x]>maxdiam)
            maxdiam=d[x];
        viz[x]=0;
    }
    d[far]=0;nr=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 max(ans,maxdiam);
}

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:73:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<centr.size();i++)
             ~^~~~~~~~~~~~~
dreaming.cpp:76:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i+1<centr.size())
            ~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 10876 KB Output is correct
2 Correct 89 ms 10872 KB Output is correct
3 Correct 45 ms 8056 KB Output is correct
4 Correct 11 ms 3968 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 17 ms 4480 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 10876 KB Output is correct
2 Correct 89 ms 10872 KB Output is correct
3 Correct 45 ms 8056 KB Output is correct
4 Correct 11 ms 3968 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 17 ms 4480 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 10876 KB Output is correct
2 Correct 89 ms 10872 KB Output is correct
3 Correct 45 ms 8056 KB Output is correct
4 Correct 11 ms 3968 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 17 ms 4480 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 6528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 10876 KB Output is correct
2 Correct 89 ms 10872 KB Output is correct
3 Correct 45 ms 8056 KB Output is correct
4 Correct 11 ms 3968 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 17 ms 4480 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 10876 KB Output is correct
2 Correct 89 ms 10872 KB Output is correct
3 Correct 45 ms 8056 KB Output is correct
4 Correct 11 ms 3968 KB Output is correct
5 Correct 10 ms 3456 KB Output is correct
6 Correct 17 ms 4480 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -