Submission #627751

# Submission time Handle Problem Language Result Execution time Memory
627751 2022-08-12T21:52:11 Z Seb Dreaming (IOI13_dreaming) C++17
0 / 100
38 ms 10308 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;
    for (auto it=grafo[v1].begin();it!=grafo[v1].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,v2.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;
        }
    }
    */
    for (i=0;i<M;i++) vec.push_back(T[i]);
    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 Incorrect 38 ms 10308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 10308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 5676 KB Output is correct
2 Correct 15 ms 5812 KB Output is correct
3 Correct 14 ms 5712 KB Output is correct
4 Correct 16 ms 5752 KB Output is correct
5 Correct 22 ms 5760 KB Output is correct
6 Correct 16 ms 6232 KB Output is correct
7 Correct 17 ms 5848 KB Output is correct
8 Correct 17 ms 5720 KB Output is correct
9 Correct 19 ms 5716 KB Output is correct
10 Correct 22 ms 5876 KB Output is correct
11 Correct 2 ms 2660 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 1 ms 2664 KB Output is correct
15 Correct 2 ms 2660 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2620 KB Output is correct
20 Runtime error 4 ms 5204 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 10308 KB Output isn't correct
2 Halted 0 ms 0 KB -