Submission #625847

# Submission time Handle Problem Language Result Execution time Memory
625847 2022-08-10T22:19:44 Z Seb Dreaming (IOI13_dreaming) C++17
0 / 100
56 ms 65536 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define f first
#define s second

vector <pair<ll,ll>> grafo[100005];
bool v[100005],flag;
ll dist=10000000000;

pair <ll,ll> ld(ll nodo, ll p) {
    pair <ll,ll> ans = {-1,-1}, aux;
    for (auto it=grafo[nodo].begin();it!=grafo[nodo].end();it++) {
        if (it->f!=p) {
            aux = ld(it->f,nodo);
            if (ans.f==-1 || ans.s<aux.s+it->s) {
                ans = aux;
                ans.s += it->s;
            }
        }
    }
    if (ans.f == -1) ans = {nodo,0};
    return ans;
}

void mid(ll v1, ll v2, ll total, ll p, ll sum) {
    if (v1==v2) flag = true;
    if (flag==false) {
        for (auto it=grafo[v1].begin();it!=grafo[v2].end();it++) {
            if (it->f!=p && flag==false) {
                mid(it->f,v2,total,v1,sum+it->s);
            }
        }
    }
    if (flag==true) {
        dist = min(dist,max(sum,total-sum));
    }
    return;
}

void dfs(ll nodo, ll p) {
    v[nodo] = true;
    for (auto it=grafo[nodo].begin();it!=grafo[nodo].end();it++) {
        if (it->f!=p) dfs(it->f,nodo);
    }
return;
}

void solve(ll nodo) {
    pair <ll,ll> v1,v2;
    v1 = ld(nodo,-1);
    v2 = ld(v1.f,-1);
    mid(v1.f,v2.f,v1.s,-1,0);
    dfs(nodo,-1);
    return;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    ll i,resp;
    vector <ll> vec;
    for (i=0;i<M;i++) {
        grafo[A[i]].push_back({B[i],T[i]});
        grafo[B[i]].push_back({A[i],T[i]});
    }
    for (i=0;i<N;i++) {
        if (v[i]==false) solve(i);
        vec.push_back(dist);
        dist=10000000000;
        flag = false;
    }
    sort(vec.begin(),vec.end());
    if (vec.size()>=3) resp = max(vec[vec.size()-1]+vec[vec.size()-2]+L,vec[vec.size()-2]+vec[vec.size()-3]+2*L);
    else if (vec.size()>=2) resp = vec[vec.size()-1]+vec[vec.size()-2]+L;
    else resp = vec[vec.size()-1];
    return resp;
}
# Verdict Execution time Memory Grader output
1 Runtime error 56 ms 31692 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 38 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 56 ms 31692 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 10292 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 38 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 56 ms 31692 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -