답안 #27216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27216 2017-07-11T04:32:38 Z top34051 꿈 (IOI13_dreaming) C++14
0 / 100
61 ms 20724 KB
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define maxn 100005
int n,m;
int mem[maxn];
int head[maxn];
long long len;
long long mx[5];
pair<int,int> rec[maxn];
vector<pair<int,int> > from[maxn];
vector<int> a[maxn];
int findhead(int x) {
    if(head[x]==x) return x;
    return head[x] = findhead(head[x]);
}
void dfs(int x,int last) {
    for(int i=0;i<from[x].size();i++) {
        if(from[x][i].first!=last) {
            mem[from[x][i].first] = mem[x] + from[x][i].second;
            rec[from[x][i].first] = {x,from[x][i].second};
            dfs(from[x][i].first,x);
        }
    }
}
pair<long long,long long> get(int x) {
    int now;
    long long path,dist;
    if(a[x].size()==0) return {0,0};
    now = a[x][0];
    memset(mem,0,sizeof(mem));
    dfs(now,0);
    for(int i=0;i<a[x].size();i++) if(mem[a[x][i]] > mem[now]) now = a[x][i];
    memset(mem,0,sizeof(mem));
    dfs(now,0);
    for(int i=0;i<a[x].size();i++) if(mem[a[x][i]] > mem[now]) now = a[x][i];
    path = mem[now];
    dist = 0;
    while(1) {
        if(dist+rec[now].second >= path/2) break;
        dist += rec[now].second;
        now = rec[now].first;
    }
//    printf("%d : %lld %lld  =>  {%lld, %lld}\n",x,path,dist,path,min(max(dist,path-dist),max(dist+rec[now].second,path-dist-rec[now].second)));
    return {path,min(max(dist,path-dist),max(dist+rec[now].second,path-dist-rec[now].second))};
}
int travelTime(int N,int M,int L,int A[],int B[],int T[]) {
    int i,j,x,y,val;
    long long ans,sum;
    pair<long long,long long> t;
    n = N; m = M; len = L;
    for(i=1;i<=n;i++) head[i] = i;
    for(i=0;i<m;i++) {
        x = A[i]; y = B[i]; val = T[i];
        x++; y++;
        head[findhead(x)] = findhead(y);
        from[x].push_back({y,val}); from[y].push_back({x,val});
    }
    for(i=1;i<=n;i++) a[findhead(i)].push_back(i);
    ans = 0;
    for(j=0;j<3;j++) mx[j] = -(long long)1e18;
    for(i=1;i<=n;i++) {
        t = get(i);
        printf("%d",1/0);
        ans = max(ans,t.first);
        for(j=0;j<3;j++) if(mx[j]<=t.second) swap(mx[j],t.second);
    }
    printf("%d",max(ans,max(mx[0]+mx[1]+len,mx[1]+mx[2]+len*2)));
}

Compilation message

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:18:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<from[x].size();i++) {
                 ~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'std::pair<long long int, long long int> get(int)':
dreaming.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<a[x].size();i++) if(mem[a[x][i]] > mem[now]) now = a[x][i];
                 ~^~~~~~~~~~~~
dreaming.cpp:36:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<a[x].size();i++) if(mem[a[x][i]] > mem[now]) now = a[x][i];
                 ~^~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:64:22: warning: division by zero [-Wdiv-by-zero]
         printf("%d",1/0);
                     ~^~
dreaming.cpp:68:64: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
     printf("%d",max(ans,max(mx[0]+mx[1]+len,mx[1]+mx[2]+len*2)));
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
dreaming.cpp:49:19: warning: unused variable 'sum' [-Wunused-variable]
     long long ans,sum;
                   ^~~
dreaming.cpp:69:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 20724 KB Execution killed with signal 4 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 20724 KB Execution killed with signal 4 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 20724 KB Execution killed with signal 4 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 43 ms 19948 KB Execution killed with signal 4 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 20724 KB Execution killed with signal 4 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 20724 KB Execution killed with signal 4 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -