Submission #27217

# Submission time Handle Problem Language Result Execution time Memory
27217 2017-07-11T04:33:08 Z top34051 Dreaming (IOI13_dreaming) C++14
0 / 100
1000 ms 15220 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);
        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:67: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:68:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 15220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 15220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 15220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 10828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 15220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 15220 KB Output isn't correct
2 Halted 0 ms 0 KB -