답안 #14783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14783 2015-06-24T01:58:38 Z progressive 꿈 (IOI13_dreaming) C++
18 / 100
62 ms 15092 KB
#include "dreaming.h"
#include <vector>
#include <algorithm>
using namespace std;
 
static const int MAXN=100100;
vector<pair<int,int> > conn[MAXN];
static int color[MAXN];
static int tp=0;
static int hdist[MAXN];
static int dist[MAXN];
static int parent[MAXN];
vector<int> samecolor[MAXN];
vector<int> radius;
void colordfs(int a,int pa,int c)
{
    color[a]=c;
    samecolor[c].push_back(a);
    for(int i=0;i<conn[a].size();i++)
    {
        int target=conn[a][i].first;
        if(target==pa) continue;
        hdist[target]=hdist[a]+conn[a][i].second;
        colordfs(target,a,c);
    }
}
void dfs(int a,int pa)
{
    parent[a]=pa;
    for(int i=0;i<conn[a].size();i++)
    {
        int target=conn[a][i].first;
        if(target==pa) continue;
        dist[target]=dist[a]+conn[a][i].second;
        dfs(target,a);
    }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    for(int i=0;i<M;i++)
    {
        conn[A[i]].push_back(make_pair(B[i],T[i]));
        conn[B[i]].push_back(make_pair(A[i],T[i]));
    }
    for(int i=0;i<N;i++)
        if(!color[i]) colordfs(i,-1,++tp);
    for(int i=1;i<=tp;i++)
    {
        int furthest=samecolor[i][0];
        for(int j=1;j<samecolor[i].size();j++)
            if(hdist[furthest]<hdist[samecolor[i][j]]) furthest=samecolor[i][j];
        dfs(furthest,-1);
        int dia=furthest;
        for(int j=0;j<samecolor[i].size();j++)
            if(dist[dia]<dist[samecolor[i][j]]) dia=samecolor[i][j];
        int radii=dist[dia];
        int res=dist[dia];
        int getr=dia;
        while(~dia)
        {
            res=min(res,max(radii-dist[dia],dist[dia]));
            dia=parent[dia];
        }
        radius.push_back(res);
    }
    sort(radius.begin(),radius.end());
    reverse(radius.begin(),radius.end());
    if(tp==1) return radius[0];
    if(tp==2) return radius[0]+radius[1]+L;
    return max(radius[0]+radius[1]+L,radius[1]+radius[2]+2*L);
}

Compilation message

dreaming.cpp: In function 'void colordfs(int, int, int)':
dreaming.cpp:19:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<conn[a].size();i++)
                 ~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:30:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<conn[a].size();i++)
                 ~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:50:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=1;j<samecolor[i].size();j++)
                     ~^~~~~~~~~~~~~~~~~~~~
dreaming.cpp:54:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<samecolor[i].size();j++)
                     ~^~~~~~~~~~~~~~~~~~~~
dreaming.cpp:58:13: warning: unused variable 'getr' [-Wunused-variable]
         int getr=dia;
             ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 15092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 15092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 15092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 11128 KB Output is correct
2 Correct 47 ms 11172 KB Output is correct
3 Correct 51 ms 11128 KB Output is correct
4 Correct 48 ms 11132 KB Output is correct
5 Correct 49 ms 11076 KB Output is correct
6 Correct 54 ms 11792 KB Output is correct
7 Correct 47 ms 11508 KB Output is correct
8 Correct 48 ms 10996 KB Output is correct
9 Correct 45 ms 11004 KB Output is correct
10 Correct 45 ms 11384 KB Output is correct
11 Correct 5 ms 4992 KB Output is correct
12 Correct 16 ms 10236 KB Output is correct
13 Correct 17 ms 10240 KB Output is correct
14 Correct 16 ms 10240 KB Output is correct
15 Correct 17 ms 10240 KB Output is correct
16 Correct 17 ms 10112 KB Output is correct
17 Correct 15 ms 9728 KB Output is correct
18 Correct 16 ms 10240 KB Output is correct
19 Correct 16 ms 10112 KB Output is correct
20 Correct 5 ms 4992 KB Output is correct
21 Correct 5 ms 4992 KB Output is correct
22 Correct 6 ms 5248 KB Output is correct
23 Correct 16 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 15092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 15092 KB Output isn't correct
2 Halted 0 ms 0 KB -