Submission #206920

# Submission time Handle Problem Language Result Execution time Memory
206920 2020-03-05T23:50:23 Z oko Dreaming (IOI13_dreaming) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;

long long n,m,l,st1,st2,vis[100005],mn=1e10,dis[100005];
vector<pair<int,int> >gr[100005];
void dfs(int x)
{
    vis[x]=1;
    for(int i=0;i<gr[x].size();i++)
    {
        int u=gr[x][i].first;
        if(vis[u])continue;
        dfs(u);
    }
}
void cal(int x)
{
    vis[x]=1;
    for(int i=0;i<gr[x].size();i++)
    {
        int u=gr[x][i].first,w=gr[x][i].second;
        if(vis[u])continue;
        cal(u);
        dis[x]=max(dis[x],dis[u]+w);
    }
}
void root(int x)
{
    vis[x]=1;
    mn=min(mn,dis[x]);
    multiset<int>ms;
    for(int i=0;i<gr[x].size();i++)
    {
        int u=gr[x][i].first,w=gr[x][i].second;
        if(vis[u])continue;
        ms.insert(dis[u]+w);
    }
    for(int i=0;i<gr[x].size();i++)
    {
        int u=gr[x][i].first,w=gr[x][i].second;
        if(vis[u])continue;
        ms.erase(ms.lower_bound(dis[u]+w));
        long long oldx=dis[x],oldu=dis[u];
        dis[x]=*--ms.end();
        dis[u]=max(dis[u],oldx+w);
        root(u);
        dis[x]=oldx;
        dis[u]=oldu;
    }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    n=N,m=M,l=L;
    for(int i=0;i<m;i++)
    {
        gr[A[i]+1].push_back({B[i]+1,T[i]});
        gr[B[i]+1].push_back({A[i]+1,T[i]});
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0&&st1==0)
        {
            dfs(i);
            st1=i;
        }
        if(vis[i]==0&&st1)
        {
            dfs(i);
            st2=i;
        }
    }
    memset(vis,0,sizeof vis);
    cal(st1);
    memset(vis,0,sizeof vis);
    root(st1);
    long long ans=mn;

    mn=1e10;
    memset(vis,0,sizeof vis);
    cal(st2);
    memset(vis,0,sizeof vis);
    root(st2);

    return ans+mn;
}

Compilation message

dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:10:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<gr[x].size();i++)
                 ~^~~~~~~~~~~~~
dreaming.cpp: In function 'void cal(int)':
dreaming.cpp:20:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<gr[x].size();i++)
                 ~^~~~~~~~~~~~~
dreaming.cpp: In function 'void root(int)':
dreaming.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<gr[x].size();i++)
                 ~^~~~~~~~~~~~~
dreaming.cpp:39:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<gr[x].size();i++)
                 ~^~~~~~~~~~~~~
/tmp/cc56MhrS.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status