Submission #251101

# Submission time Handle Problem Language Result Execution time Memory
251101 2020-07-20T08:22:15 Z huuducpro Dreaming (IOI13_dreaming) C++14
Compilation error
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;
        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 (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);

    }
    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:67:1: error: unterminated comment
 /*int main()
 ^
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:26:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<X.size();i++)
                  ~^~~~~~~~~
dreaming.cpp:33:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<X.size();i++)
                  ~^~~~~~~~~