답안 #251103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251103 2020-07-20T08:33:07 Z huuducpro 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
//#include "dreaming.h"
using namespace std;
int n,vs[100002],fa[100002],d[100002];
typedef pair <int,int> pp;
vector <pp> adj[100002];
vector <int> X;
void dfs(int u)
{
    vs[u]=1;
    X.push_back(u);
    for (int i=0;i<adj[u].size();i++)
    {
        int v=adj[u][i].first;
        if (vs[v]==1) continue;
        fa[v]=u;d[v]=d[u]+adj[u][i].second;
        dfs(v);
    }
}
int get(int r)
{
    X.clear();
    dfs(r);
    int p=r;
    for (int i=0;i<X.size();i++)
    {
        if (d[X[i]]>d[p]) p=X[i];
        vs[X[i]]=0;
    }
    X.clear();
    r=p;fa[r]=0;d[r]=0;dfs(p);
    for (int i=0;i<X.size();i++)
        if (d[X[i]]>d[p]) p=X[i];
    int ans=d[p];int w=d[p];
    while (p>0)
    {
        ans=min(ans,max(d[p],w-d[p]));
        p=fa[p];
    }
    return ans;

}
int travelTime(int nn,int m,int l,int A[],int B[],int T[])
{
    n=nn;
    for (int i=0;i<m;i++)
    {
        A[i]++;B[i]++;
        adj[A[i]].push_back({B[i],T[i]});
        adj[B[i]].push_back({A[i],T[i]});
    }
    vector <int> P;
    for (int i=1;i<=n;i++)
    {
        if (vs[i]==1) continue;
        int t=get(i);
       // cout<<i-1<<' '<<t<<'\n';
        P.push_back(t);

    }
    int res=0;
    for (int i=1;i<=n;i++) res=max(res,d[i]);
    sort(P.begin(),P.end(),greater<int>());
    if (P.size()==1) return res;
    if (P.size()>1) res=max(res,P[0]+P[1]+l);
    if (P.size()>2) res=max(res,P[1]+P[2]+2*l);
    return res;
}
/*int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    freopen("dreaming1.inp","r",stdin);
    freopen("dreaming1.out","w",stdout);
     int n,m,l;cin>>n>>m>>l;
     int a[100002],b[100002],t[100002];
    for (int i=0;i<m;i++) cin>>a[i]>>b[i]>>t[i];
    cout<<travelTime(n,m,l,a,b,t);

}*/

Compilation message

dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:12:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<adj[u].size();i++)
                  ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'int get(int)':
dreaming.cpp:25:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<X.size();i++)
                  ~^~~~~~~~~
dreaming.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<X.size();i++)
                  ~^~~~~~~~~
/tmp/ccBv18wk.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status