답안 #584041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584041 2022-06-26T17:02:25 Z gangmtfk 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include<dreaming.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
const int maxn=100002;
int n,m,l,ma,mark,cntcp,cp[maxn],dis[maxn][4],dia,ret;
vector<pii> a[maxn]; bool in[maxn][4];
void dfs(int u, int time)
{
    if(time==3) ret=min(ret,max(dis[u][2],dis[u][3]));
    in[u][time]=true;
    for(auto v:a[u])
    {
        if(in[v.fi][time]) continue;
        dis[v.fi][time]=dis[u][time]+v.se;
        if(dis[v.fi][time]>ma)
        {
            ma=dis[v.fi][time];
            mark=v.fi;
        }
        dfs(v.fi,time);
    }
}
int maxdis(int root)
{
    memset(dis,0,sizeof(dis));
    mark=0; ma=0; ret=1e9;
    dfs(root,1);
    int A=mark; mark=0; ma=0;
    dfs(A,2); dia=max(dia,ma);
    int B=mark; mark=0; ma=0;
    dfs(B,3);
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  	freopen("DREAMING.INP","r",stdin);
  	freopen("DREAMING.OUT","w",stdout);
    cin >> n >> m >> l;
    for(int i=1; i<=m; i++)
    {
        int x,y,z; cin >> x >> y >> z;
        a[x].push_back({y,z});
        a[y].push_back({x,z});
    }
    for(int i=0; i<n; i++)
    {
        if(in[i][3]) continue;
        cp[++cntcp]=maxdis(i);
    }
    if(cntcp==1)
    {
        cout << dia;
        return 0;
    }
    sort(cp+1,cp+1+cntcp,greater<int>());
    if(cntcp==2) cout << max(dia,l+cp[1]+cp[2]);
    else cout << max(dia,max(2*l+cp[2]+cp[3],l+cp[1]+cp[2]));
    //for(int i=1; i<=cntcp; i++) cout << cp[i]<< " ";
    return 0;
}

Compilation message

dreaming.cpp: In function 'int main()':
dreaming.cpp:40:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |    freopen("DREAMING.INP","r",stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:41:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |    freopen("DREAMING.OUT","w",stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cccgrYpy.o: in function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccK873zz.o:grader.c:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccK873zz.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status