답안 #875548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875548 2023-11-20T03:32:12 Z hmm789 꿈 (IOI13_dreaming) C++14
18 / 100
45 ms 15548 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

int dist[100000], prv[100000], idx;
vector<pair<int, int>> adj[100000];
vector<int> v, path, tmp;
void dfs(int x, int p) {
    if(dist[x] > dist[idx]) idx = x;
    tmp.push_back(x);
    prv[x] = p;
    for(auto i : adj[x]) if(i.first != p) {
        if(dist[i.first] == -1) {
            dist[i.first] = dist[x]+i.second;
            dfs(i.first, x);
        }
    }
}

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]});
    }
    memset(dist, -1, sizeof(dist));
    for(int i = 0; i < N; i++) {
        if(dist[i] != -1) continue;
        idx = i;
        dist[i] = 0;
        dfs(i, -1);
        while(tmp.size()) {
            dist[tmp.back()] = -1;
            tmp.pop_back();
        }
        dist[idx] = 0;
        dfs(idx, -1);
        tmp.clear();
        int cur = (int)1e9;
        for(int j = idx; j != -1; j = prv[j]) path.push_back(j);
        for(int j : path) cur = min(cur, max(dist[j], dist[idx]-dist[j]));
        v.push_back(cur);
        path.clear();
    }
    sort(v.begin(), v.end(), greater<int>());
    if(v.size() == 1) return v[0];
    if(v.size() == 2) return v[0]+v[1]+L;
    return max(v[0]+v[1]+L, v[1]+v[2]+2*L);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 15548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 15548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 7392 KB Output is correct
2 Correct 14 ms 7384 KB Output is correct
3 Correct 14 ms 7392 KB Output is correct
4 Correct 14 ms 7368 KB Output is correct
5 Correct 14 ms 7388 KB Output is correct
6 Correct 15 ms 7796 KB Output is correct
7 Correct 15 ms 7540 KB Output is correct
8 Correct 13 ms 7392 KB Output is correct
9 Correct 15 ms 7272 KB Output is correct
10 Correct 14 ms 7512 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 4 ms 5080 KB Output is correct
13 Correct 4 ms 5216 KB Output is correct
14 Correct 4 ms 5080 KB Output is correct
15 Correct 5 ms 5076 KB Output is correct
16 Correct 4 ms 5080 KB Output is correct
17 Correct 4 ms 5080 KB Output is correct
18 Correct 4 ms 5192 KB Output is correct
19 Correct 4 ms 5080 KB Output is correct
20 Correct 1 ms 4528 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 4 ms 5092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 15548 KB Output isn't correct
2 Halted 0 ms 0 KB -