답안 #574678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
574678 2022-06-09T08:16:33 Z talant117408 꿈 (IOI13_dreaming) C++17
18 / 100
73 ms 11884 KB
#include "dreaming.h"
#include <bits/stdc++.h>

//~ #ifndef EVAL
//~ #include "grader.cpp"
//~ #endif
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
#define pb                  push_back
#define mp                  make_pair
#define lb                  lower_bound
#define ub                  upper_bound
#define all(v)              (v).begin(),(v).end()
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'

const int N = 1e5+7;
int used[N];
int n, compN, comp[N], compLowest[N];
pii compEnds[N];
vector <pii> graph[N];

void dfs(int v, int p) {
    used[v] = 1;
    comp[v] = compN;
    for (auto to : graph[v]) {
        if (to.first == p) continue;
        dfs(to.first, v);
    }
}

int df, vf;
int distFrom[N];

void get_furthest(int v, int p, int dist = 0) {
    if (dist > df) {
        df = dist;
        vf = v;
    }
    for (auto to : graph[v]) {
        if (to.first == p) continue;
        get_furthest(to.first, v, dist+to.second);
    }
}

void calc_dist(int v, int p = -1, int d = 0) {
    distFrom[v] = max(distFrom[v], d);
    for (auto to : graph[v]) {
        if (to.first == p) continue;
        calc_dist(to.first, v, d+to.second);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n = N;
    for (int i = 0; i < M; i++) {
        graph[A[i]].pb(mp(B[i], T[i]));
        graph[B[i]].pb(mp(A[i], T[i]));
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!used[i]) {
            compLowest[++compN] = 2e9;
            dfs(i, i);
            
            df = vf = 0;
            get_furthest(i, i);
            compEnds[compN].first = vf;
            
            int q = vf;
            df = vf = 0;
            get_furthest(q, q);
            compEnds[compN].second = vf;
            
            ans = max(ans, df);
        }
    }
    for (int i = 1; i <= compN; i++) {
        calc_dist(compEnds[i].first);
        calc_dist(compEnds[i].second);
    }
    for (int i = 1; i <= n; i++) {
        if (compLowest[comp[i]] > distFrom[i]) {
            compLowest[comp[i]] = distFrom[i];
        }
    }
    vector <int> tmp;
    for (int i = 1; i <= compN; i++) {
        tmp.pb(compLowest[i]);
    }
    sort(tmp.rbegin(), tmp.rend());
    if (sz(tmp) > 1) {
        ans = max(ans, tmp[0]+L+tmp[1]);
    }
    if (sz(tmp) > 2) {
        ans = max(ans, tmp[1]+L+L+tmp[2]);
    }
    return ans;
}

//~ int main() {
    //~ int n, m, l;
    //~ cin >> n >> m >> l;
    //~ int x[m], y[m], t[m];
    //~ for (int i = 0; i < m; i++) {
        //~ cin >> x[i] >> y[i] >> t[i];
    //~ }
    //~ cout << travelTime(n, m, l, x, y, t);
//~ }
/*
12 8 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 11856 KB Output is correct
2 Correct 58 ms 11884 KB Output is correct
3 Correct 34 ms 8680 KB Output is correct
4 Correct 9 ms 3976 KB Output is correct
5 Correct 10 ms 3464 KB Output is correct
6 Correct 15 ms 4692 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 2 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 11856 KB Output is correct
2 Correct 58 ms 11884 KB Output is correct
3 Correct 34 ms 8680 KB Output is correct
4 Correct 9 ms 3976 KB Output is correct
5 Correct 10 ms 3464 KB Output is correct
6 Correct 15 ms 4692 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 7196 KB Output is correct
2 Correct 28 ms 7220 KB Output is correct
3 Correct 26 ms 7144 KB Output is correct
4 Correct 26 ms 7124 KB Output is correct
5 Correct 21 ms 7156 KB Output is correct
6 Correct 27 ms 7628 KB Output is correct
7 Correct 26 ms 7380 KB Output is correct
8 Correct 21 ms 7140 KB Output is correct
9 Correct 27 ms 7116 KB Output is correct
10 Correct 21 ms 7380 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 6 ms 5584 KB Output is correct
13 Correct 7 ms 5652 KB Output is correct
14 Correct 6 ms 5584 KB Output is correct
15 Correct 8 ms 5584 KB Output is correct
16 Correct 6 ms 5584 KB Output is correct
17 Correct 6 ms 5480 KB Output is correct
18 Correct 6 ms 5584 KB Output is correct
19 Correct 6 ms 5584 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 2 ms 2772 KB Output is correct
23 Correct 6 ms 5584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 2 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 11856 KB Output is correct
2 Correct 58 ms 11884 KB Output is correct
3 Correct 34 ms 8680 KB Output is correct
4 Correct 9 ms 3976 KB Output is correct
5 Correct 10 ms 3464 KB Output is correct
6 Correct 15 ms 4692 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -