답안 #482413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482413 2021-10-24T13:15:29 Z Spade1 꿈 (IOI13_dreaming) C++17
0 / 100
40 ms 12356 KB
#include <bits/stdc++.h>
#include "dreaming.h"
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
using namespace std;

vector<pii> adj[100010];
bool visited[100010];

int max_dis, min_dis;
int u, v, node;

void dfs(int i, int prt, int dis) {
    visited[i] = 1;
    if (dis > max_dis) {
        u = i;
        max_dis = dis;
    }
    for (auto j : adj[i]) {
        if (j.st == prt) continue;
        dfs(j.st, i, dis + j.nd);
    }
}

int dfs2(int i, int prt, int dis) {
    if (i == v) {
        min_dis = dis;
        return 0;
    }
    for (auto j : adj[i]) {
        if (j.st == prt) continue;
        int k = dfs2(j.st, i, dis + j.nd);
        if (k == -1) continue;
        k += j.nd;
        min_dis = min(max(dis, k), min_dis);
        return k;
    }

    return -1;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for (int i = 0; i < M; ++i) {
        adj[A[i]].push_back({B[i], T[i]});
        adj[B[i]].push_back({A[i], T[i]});
    }

    int mx1 = INT_MIN, mx2 = INT_MIN, mx3 = INT_MIN;

    for (int i = 0; i < N; ++i) {
        if (visited[i]) continue;
        max_dis = 0, u = i;
        dfs(i, -1, 0);
        max_dis = 0, v = u;
        dfs(v, -1, 0);
        min_dis = INT_MAX;
        dfs2(u, -1, 0);
        if (min_dis > mx1) {
            mx3 = mx2;
            mx2 = mx1;
            mx1 = min_dis;
        }
        else if (min_dis > mx2) {
            mx3 = mx2;
            mx2 = min_dis;
        }
        else if (min_dis > mx3) {
            mx3 = min_dis;
        }
    }

    return max(mx1 + mx2 + L, mx2 + mx3 + 2*L);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 12356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 12356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5024 KB Output is correct
2 Correct 17 ms 5068 KB Output is correct
3 Correct 15 ms 5068 KB Output is correct
4 Correct 15 ms 5068 KB Output is correct
5 Correct 20 ms 5072 KB Output is correct
6 Correct 20 ms 5116 KB Output is correct
7 Correct 17 ms 5180 KB Output is correct
8 Correct 16 ms 4920 KB Output is correct
9 Correct 15 ms 5000 KB Output is correct
10 Correct 15 ms 5128 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 3 ms 2764 KB Output is correct
13 Correct 3 ms 2764 KB Output is correct
14 Correct 3 ms 2764 KB Output is correct
15 Correct 3 ms 2764 KB Output is correct
16 Correct 2 ms 2764 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 3 ms 2764 KB Output is correct
19 Correct 4 ms 2764 KB Output is correct
20 Incorrect 2 ms 2636 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 12356 KB Output isn't correct
2 Halted 0 ms 0 KB -