답안 #595204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
595204 2022-07-13T12:39:05 Z shrimb 꿈 (IOI13_dreaming) C++17
18 / 100
87 ms 20996 KB
#include "bits/stdc++.h"
#include "dreaming.h"
using namespace std;

const int maxn = 100001;

vector<pair<int,int>> adj[maxn];

/*

answer can be:

1- biggest simple path which exists
2- 2 biggest path from roots + L
3- 2nd and 3rd biggest paths from roots + 2L

*/

int A1 = 0, A2 = 0, A3 = 0;
int id = 1;
int cmp[maxn];
int dist[maxn];
int distu[maxn];

void dfs (int cur, int par) {
    multiset<int> mx;
    for (auto [j, w] : adj[cur]) {
        if (!cmp[j]) {
            cmp[j] = id;
            dfs(j, cur);
            dist[cur] = max(dist[cur], dist[j] + w);
            mx.insert(dist[j] + w);
            if (mx.size() > 2) mx.erase(mx.begin());
            if (mx.size() == 2) {
                A1 = max(A1, *mx.begin() + *++mx.begin());
            }
        }
    }

}

void dfs2 (int cur, int par) {
    multiset<int> mxs;
    for (auto [j, w] : adj[cur]) {
        mxs.insert(dist[j] + w);
    }
    for (auto [j, w] : adj[cur]) {
        if (j != par) {
            int v = dist[j] + w;
            mxs.erase(mxs.find(v));
            if (mxs.size()) distu[j] = max(distu[j], *--mxs.end() + w);
            distu[j] = max(distu[j], distu[cur] + w);
            mxs.insert(v);
        }
    }
    for (auto [j, w] : adj[cur]) {
        if (j != par) dfs2(j, cur);
    }
}

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

    for (int i = 0 ; i < N ; i++) {
        if (cmp[i] == 0) {
            cmp[i] = id;
            dfs(i, -1);
            dfs2(i, -1);
            id++;
        }
    }

    int vals[id];
    memset(vals, -1, sizeof vals);

    for (int i = 0 ; i < N ; i++) {
        // cerr << "debug dist[" << i << "]: " << dist[i] << endl;
        if (vals[cmp[i]] == -1) {
            vals[cmp[i]] = max(distu[i],dist[i]);
        } else {
            vals[cmp[i]] = min(vals[cmp[i]], max(distu[i],dist[i]));
        }
    }

    sort(vals + 1, vals + id, greater<int>());

    if (id > 2) {
        A2 = vals[1] + vals[2] + L;
    }
    if (id > 3) {
        A3 = vals[2] + vals[3] + L + L;
    }

    return max({A1, A2, A3});
}
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 20996 KB Output is correct
2 Correct 63 ms 20072 KB Output is correct
3 Correct 44 ms 19560 KB Output is correct
4 Correct 8 ms 5204 KB Output is correct
5 Correct 7 ms 3924 KB Output is correct
6 Correct 15 ms 6612 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 87 ms 20996 KB Output is correct
2 Correct 63 ms 20072 KB Output is correct
3 Correct 44 ms 19560 KB Output is correct
4 Correct 8 ms 5204 KB Output is correct
5 Correct 7 ms 3924 KB Output is correct
6 Correct 15 ms 6612 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 6228 KB Output is correct
2 Correct 23 ms 6228 KB Output is correct
3 Correct 29 ms 6328 KB Output is correct
4 Correct 36 ms 6320 KB Output is correct
5 Correct 34 ms 6396 KB Output is correct
6 Correct 25 ms 6532 KB Output is correct
7 Correct 26 ms 6444 KB Output is correct
8 Correct 25 ms 6372 KB Output is correct
9 Correct 24 ms 6156 KB Output is correct
10 Correct 25 ms 6352 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 8 ms 4052 KB Output is correct
13 Correct 10 ms 4188 KB Output is correct
14 Correct 9 ms 4052 KB Output is correct
15 Correct 9 ms 4052 KB Output is correct
16 Correct 6 ms 3924 KB Output is correct
17 Correct 6 ms 3680 KB Output is correct
18 Correct 9 ms 4196 KB Output is correct
19 Correct 5 ms 4052 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 5 ms 3924 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 87 ms 20996 KB Output is correct
2 Correct 63 ms 20072 KB Output is correct
3 Correct 44 ms 19560 KB Output is correct
4 Correct 8 ms 5204 KB Output is correct
5 Correct 7 ms 3924 KB Output is correct
6 Correct 15 ms 6612 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -