답안 #27213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27213 2017-07-11T04:27:54 Z top34051 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.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))};
}
main() {
    int i,j,x,y,val;
    long long ans,sum;
    pair<long long,long long> t;
    scanf("%d%d%lld",&n,&m,&len);
    for(i=1;i<=n;i++) head[i] = i;
    for(i=0;i<m;i++) {
        scanf("%d%d%d",&x,&y,&val);
        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:17: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:32: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:35: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: At global scope:
dreaming.cpp:46:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
dreaming.cpp: In function 'int main()':
dreaming.cpp:63:22: warning: division by zero [-Wdiv-by-zero]
         printf("%d",1/0);
                     ~^~
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:48:19: warning: unused variable 'sum' [-Wunused-variable]
     long long ans,sum;
                   ^~~
dreaming.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%lld",&n,&m,&len);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&x,&y,&val);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
/tmp/ccQqpAZc.o: In function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc6Lgpyx.o:grader.c:(.text.startup+0x0): first defined here
/tmp/cc6Lgpyx.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status