Submission #590975

# Submission time Handle Problem Language Result Execution time Memory
590975 2022-07-06T16:22:44 Z KrisjanisP Dreaming (IOI13_dreaming) C++17
18 / 100
198 ms 25712 KB
#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
    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 = 1e9;
        for(ll v: nodes)
        {
            ll mxDepth = 0;
            for(auto& [u,w]: AL[v])
                mxDepth=max(mxDepth, maxDepth(u,v)+w);
            mnMxDepth = min(mnMxDepth, mxDepth);
        }
        ecc.push_back(mnMxDepth);
    }
    //cout<<"ecc: "; for(ll x: ecc) cout<<x<<" "; cout<<"\n";
    sort(ecc.begin(),ecc.end(),greater<ll>());
    ll 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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 198 ms 25712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 198 ms 25712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 9436 KB Output is correct
2 Correct 51 ms 9460 KB Output is correct
3 Correct 67 ms 9772 KB Output is correct
4 Correct 61 ms 9908 KB Output is correct
5 Correct 46 ms 9828 KB Output is correct
6 Correct 49 ms 10780 KB Output is correct
7 Correct 53 ms 10240 KB Output is correct
8 Correct 45 ms 9692 KB Output is correct
9 Correct 66 ms 9588 KB Output is correct
10 Correct 53 ms 10080 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 11 ms 3916 KB Output is correct
13 Correct 9 ms 3944 KB Output is correct
14 Correct 10 ms 3932 KB Output is correct
15 Correct 10 ms 3936 KB Output is correct
16 Correct 10 ms 3848 KB Output is correct
17 Correct 9 ms 3916 KB Output is correct
18 Correct 13 ms 3916 KB Output is correct
19 Correct 10 ms 3916 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2664 KB Output is correct
23 Correct 10 ms 3916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 198 ms 25712 KB Output isn't correct
2 Halted 0 ms 0 KB -