답안 #251099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251099 2020-07-20T08:18:04 Z huuducpro 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.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 (auto i=0;i<adj[u].size();i++)
    {
        int v=adj[u][i].first;
        if (vs[v]==1) continue;
        vs[v]=1;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 (auto 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 (auto 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);

    }
    sort(P.begin(),P.end(),greater<int>());
    if (P.size()==1) return P[0];
    if (P.size()==2) return P[0]+P[1]+l;
    return max(P[0]+P[1]+l,P[1]+P[2]+2*l);
}
/*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];
    for (int i=0;i<m;i++) cin>>b[i];
    for (int i=0;i<m;i++) cin>>t[i];
    cout<<travelTime(n,m,l,a,b,t);

}*/

Compilation message

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