Submission #441285

# Submission time Handle Problem Language Result Execution time Memory
441285 2021-07-04T20:45:52 Z julian33 Dreaming (IOI13_dreaming) C++14
0 / 100
65 ms 15544 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cerr<<vars<<" = ";
    string delim="";
    (...,(cerr<<delim<<values,delim=", "));
    cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif

#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}

const int mxN=1e5+5;

vector<pii> graph[mxN];
ll dist[mxN],r=2e9;
int ep,seen[mxN],good[mxN],st;
vector<int> path;

void dfs(int at,int p){
    path.pb(dist[at]);
    seen[at]=1;
    if(dist[at]>dist[ep])
        ep=at;
    for(pii &i:graph[at]){
        if(i.first!=p){
            dist[i.first]=dist[at]+i.second;
            dfs(i.first,at);
        }
    }
}

void get_rad(int at,int p){
    if(at==ep)
        good[at]=1;
    for(pii &i:graph[at]){
        if(i.first==p)
            continue;
        get_rad(i.first,at);
        good[at]|=good[i.first];
    }
    if(good[at]){
        mina(r,max(dist[at],dist[ep]-dist[at]));
    }
}

void merge(pii &a,pii &b,int L){
    if(max(a.first,b.first)>a.second+b.second+L){
        if(a.first<b.first)
            swap(a,b);
    } else if(max(a.first,b.first)<a.second+b.second+L){
        a.second=min(max(a.second,a.first-a.second+L),max(b.second,a.first-b.second+L));
        a.first=a.second+b.second+L;
    } else{
        int k=a.first<b.first?b.second:a.second;
        a.second=min(min(max(a.second,a.first-a.second+L),max(b.second,a.first-b.second+L)),k);
        a.first=max(a.first,b.first);
    }
}

int travelTime(int N,int M,int L,int A[],int B[],int T[]){
    for(int i=0;i<M;i++){
        graph[A[i]].pb({B[i],T[i]});
        graph[B[i]].pb({A[i],T[i]});
    }
    vector<pii> all;
    for(int i=0;i<N;i++){
        if(seen[i])
            continue;
        ep=N;
        dfs(i,-1);
        path.clear();
        dist[ep]=0; st=ep;
        dfs(ep,-1);
        r=2e9;
        get_rad(st,-1);
        all.pb({dist[ep],r});
        path.clear();
    }
    pii ans=all[0];
    for(int i=1;i<sz(all);i++){
        merge(ans,all[i],L);
    }
    return ans.first;
}
# Verdict Execution time Memory Grader output
1 Correct 56 ms 15544 KB Output is correct
2 Correct 65 ms 15484 KB Output is correct
3 Correct 37 ms 11092 KB Output is correct
4 Correct 9 ms 4556 KB Output is correct
5 Correct 7 ms 3660 KB Output is correct
6 Correct 14 ms 5592 KB Output is correct
7 Incorrect 2 ms 2636 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Incorrect 2 ms 2636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 15544 KB Output is correct
2 Correct 65 ms 15484 KB Output is correct
3 Correct 37 ms 11092 KB Output is correct
4 Correct 9 ms 4556 KB Output is correct
5 Correct 7 ms 3660 KB Output is correct
6 Correct 14 ms 5592 KB Output is correct
7 Incorrect 2 ms 2636 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 7000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Incorrect 2 ms 2636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 15544 KB Output is correct
2 Correct 65 ms 15484 KB Output is correct
3 Correct 37 ms 11092 KB Output is correct
4 Correct 9 ms 4556 KB Output is correct
5 Correct 7 ms 3660 KB Output is correct
6 Correct 14 ms 5592 KB Output is correct
7 Incorrect 2 ms 2636 KB Output isn't correct
8 Halted 0 ms 0 KB -