Submission #591019

#TimeUsernameProblemLanguageResultExecution timeMemory
591019KrisjanisPDreaming (IOI13_dreaming)C++14
77 / 100
1092 ms34932 KiB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll,ll>;
const ll MX = 100000;
vector<ii> AL[MX];
bool visited[MX];

map<ii,ll> maxDepthMem;
// returns the maximum depth
ll maxDepth(ll v, ll p)
{
    if(maxDepthMem.count({v,p}))
        return maxDepthMem[{v,p}];
    ll res = 0;
    for(auto& [u,w]: AL[v])
    {
        if(u==p) continue;
        res = max(res, maxDepth(u,v)+w);
    }
    maxDepthMem[{v,p}] = res;
    return res;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(ll i=0;i<M;i++)
    {
        ll a = A[i], b=B[i], w=T[i];
        AL[a].push_back({b,w});
        AL[b].push_back({a,w});
    }
    vector<ll> ecc; // eccentricity vector
    ll res = 0;
    for(ll i=0;i<N;i++)
    {
        if(visited[i]) continue;
        vector<ll> nodes;
        queue<ll> q;
        q.push(i);
        visited[i]=1;
        nodes.push_back(i);
        while(!q.empty())
        {
            ll v = q.front(); q.pop();
            for(auto& [u,w]: AL[v])
            {
                if(visited[u]) continue;
                q.push(u);
                visited[u]=1;
                nodes.push_back(u);
            }
        }
        //cout<<"nodes: "; for(ll v: nodes) cout<<v<<" "; cout<<"\n";
        ll mnMxDepth = 1e10;
        for(ll v: nodes)
        {
            ll mxDepth = 0;
            for(auto& [u,w]: AL[v])
                mxDepth=max(mxDepth, maxDepth(u,v)+w);
            res = max(res,mxDepth);
            mnMxDepth = min(mnMxDepth, mxDepth);
        }
        ecc.push_back(mnMxDepth);
    }
    sort(ecc.begin(),ecc.end(),greater<ll>());
    //cout<<"ecc: "; for(ll x: ecc) cout<<x<<" "; cout<<"\n";
    res = max(res, ecc[0]);
    if(ecc.size()>=2) res=max(res,ecc[0]+ecc[1]+L);
    if(ecc.size()>=3) res=max(res,ecc[1]+ecc[2]+2*L);
    return res;
}

Compilation message (stderr)

dreaming.cpp: In function 'll maxDepth(ll, ll)':
dreaming.cpp:17:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   17 |     for(auto& [u,w]: AL[v])
      |               ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:46:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |             for(auto& [u,w]: AL[v])
      |                       ^
dreaming.cpp:59:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   59 |             for(auto& [u,w]: AL[v])
      |                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...