답안 #27219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27219 2017-07-11T04:58:29 Z top34051 꿈 (IOI13_dreaming) C++14
0 / 100
1000 ms 17776 KB
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define maxn 100005
int head[maxn];
long long len[maxn];
pair<int,long long> rec[maxn];
vector<pair<int,long long> > from[maxn];
vector<int> p[maxn];
vector<long long> a;
void dfs(int x,int last) {
    int i;
    for(i=0;i<from[x].size();i++) {
        if(from[x][i].first!=last) {
            len[from[x][i].first] = len[x] + from[x][i].second;
            rec[from[x][i].first] = {x, from[x][i].second};
            dfs(from[x][i].first,x);
        }
    }
}
int findhead(int x) {
    if(head[x]==x) return x;
    return head[x] = findhead(head[x]);
}
bool cmp(int x,int y) {
    return x>y;
}
int travelTime(int N,int M,int L,int A[],int B[],int T[]) {
    int i,j;
    long long sum,now,full,half,ans;
    for(i=0;i<N;i++) head[i] = i;
    for(i=0;i<M;i++) from[A[i]].push_back({B[i],T[i]}), from[B[i]].push_back({A[i],T[i]}), head[findhead(A[i])] = findhead(B[i]);
    for(i=0;i<N;i++) p[findhead(i)].push_back(i);
    ans = 0;
    for(i=0;i<N;i++) {
        if(p[i].size()==0) continue;
        for(j=0;j<p[i].size();j++) len[p[i][j]] = 0, rec[p[i][j]] = {-1, -1};
        //First
        now = p[i][0];
        dfs(now,-1);
        //Second
        for(j=0;j<p[i].size();j++) if(len[p[i][j]]>len[now]) now = p[i][j];
        for(j=0;j<p[i].size();j++) len[p[i][j]] = 0;
        dfs(now,-1);
        //Track
        for(j=0;j<p[i].size();j++) if(len[p[i][j]]>len[now]) now = p[i][j];
        full = half = len[now]; sum = 0;
        while(now!=-1) {
            sum += rec[now].first;
            now = rec[now].first;
            half = min(half,max(sum,full-sum));
        }
        ans = max(ans,full);
        a.push_back(half);
    }
    sort(&a[0],&a[a.size()],cmp);
    if(a.size()>1) ans = max(ans,a[0]+a[1]+L);
    if(a.size()>2) ans = max(ans,a[1]+a[2]+L+L);
    printf("%lld",ans);
}

Compilation message

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:13:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<from[x].size();i++) {
             ~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:37:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<p[i].size();j++) len[p[i][j]] = 0, rec[p[i][j]] = {-1, -1};
                 ~^~~~~~~~~~~~
dreaming.cpp:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<p[i].size();j++) if(len[p[i][j]]>len[now]) now = p[i][j];
                 ~^~~~~~~~~~~~
dreaming.cpp:43:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<p[i].size();j++) len[p[i][j]] = 0;
                 ~^~~~~~~~~~~~
dreaming.cpp:46:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<p[i].size();j++) if(len[p[i][j]]>len[now]) now = p[i][j];
                 ~^~~~~~~~~~~~
dreaming.cpp:60:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 17776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 17776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 17776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1072 ms 9672 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 17776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 17776 KB Time limit exceeded
2 Halted 0 ms 0 KB -