답안 #881096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881096 2023-11-30T14:49:00 Z sysia 꿈 (IOI13_dreaming) C++17
0 / 100
35 ms 16792 KB
//Sylwia Sapkowska
#include <bits/stdc++.h>
#include "dreaming.h"
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;

void __print(int x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << "'" << x << "'";}
void __print(const char *x) {cout << '"' << x << '"';}
void __print(const string &x) {cout << '"' << x << '"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ", "; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? ", " : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef pair<int, int> T;
const int oo = 1e9+7, K = 30;
const int mod = 998244353;

int travelTime(int n, int m, int L, int A[], int B[], int TT[]) {
    vector<vector<T>>g(n);
    for (int i = 0; i<m; i++){
        debug(A[i], B[i], TT[i]);
        g[A[i]].emplace_back(B[i], TT[i]);
        g[B[i]].emplace_back(A[i], TT[i]);
    }
    vector<bool>vis(n);
    vector<int>depth(n), par(n);
    T curr = {-oo, -oo};
    function<void(int, int)>dfs = [&](int v, int pa){
        vis[v] = 1;
        par[v] = pa;
        curr = max(curr, {depth[v], v});
        for (auto [x, c]: g[v]){
            if (x == pa) continue;
            depth[x] = depth[v]+c;
            dfs(x, v);
        }
    };
    int mx1 = 0, mx2 = 0;
    for (int i = 0; i<n; i++){
        if (!vis[i]){
            curr = {-oo, -oo};
            dfs(i, i);
            int R = curr.second;
            depth[R] = 0;
            curr = {-oo, -oo};
            dfs(R, R);
            int L = curr.second;
            debug(L, R);
            int w = depth[L];
            int v = L, c = oo;
            while (1){
                c = min(c, max(depth[v], w-depth[v]));
                v = par[v];
                if (v == R) break;
            }
            debug(w, c);
            if (c >= mx1){
                mx2 = mx1;
                mx1 = c;
            } else if (c >= mx2){
                mx2 = c;
            }
        }
    }
    // debug(mx1, mx2, L);
    return mx1+mx2+(m == n-1 ? 0 : L);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 16792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 16792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 5976 KB Output is correct
2 Incorrect 14 ms 6080 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 16792 KB Output isn't correct
2 Halted 0 ms 0 KB -