Submission #496619

# Submission time Handle Problem Language Result Execution time Memory
496619 2021-12-21T16:43:18 Z Karliver Dreaming (IOI13_dreaming) C++17
0 / 100
52 ms 15132 KB
    
#include <bits/stdc++.h>
#include "dreaming.h"
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace  std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
#define sz(x) (int)x.size()
#define ff first
#define se second
#define mp make_pair
using ll = long long;
int mod = (ll)1e9 + 7;
const int INF = 1e9 + 1;

const double eps = 1e-7;

template <class T> using V = vector<T>;  
template <class T> using VV = V<V<T>>;  
template<class T, size_t SZ> using AR = array<T, SZ>;
template<class T> using PR = pair<T, T>;
template <typename XPAX>
bool ckma(XPAX &x, XPAX y) {
    return (x < y ? x = y, 1 : 0);
}
template <typename XPAX>
bool ckmi(XPAX &x, XPAX y) {
    return (x > y ? x = y, 1 : 0);
}
V<PR<int>> g[100002];
int dep[100002];
V<bool> vis(100002);
PR<int> m1[100002], m2[100002];
int mi;
void dfs(int v, int p) {
    vis[v]=1;
    
    for(auto [c, w] : g[v]) {
        if(c == p)continue;
        dep[c] = dep[v] + w;
        dfs(c, v); 
        int Q = w + m1[c].ff;
        if(Q > m1[v].ff) {
            swap(m1[v], m2[v]);
            m1[v] = mp(Q, c);
        }
        else if(Q > m2[v].ff) {
            m2[v] = mp(Q, c);
        }

    }

}


void dfs2(int v, int p, int cmx) {
    ckmi(mi, cmx);

    for(auto [c, w] : g[v]) {
        if(c == p)continue;
        int nw = (c == m1[v].se ? m2[v].ff : m1[v].ff) + w;
        ckma(nw, dep[c]);
        ckma(nw, m1[c].ff);
        dfs2(c, v, nw);
    }
}

int travelTime(int N, int M, int L,
        int A[], int B[], int T[]) {

    forn(i, M) {
        g[A[i]].push_back({B[i], T[i]});
        g[B[i]].push_back({A[i], T[i]});
    }
    V<int> root;
    forn(i, N) {
        if(!vis[i]) {
            root.push_back(i);
            dfs(i, -1);
        }
    }   
    int ret = L;
    for(auto c : root) {
        mi = INF;
        dfs2(c, -1, m1[c].ff);
        ret += mi;
    }


    return ret;
}
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 15132 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 52 ms 15132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 7716 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 52 ms 15132 KB Output isn't correct
2 Halted 0 ms 0 KB -