답안 #553905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553905 2022-04-27T09:41:17 Z elazarkoren 꿈 (IOI13_dreaming) C++17
14 / 100
51 ms 65536 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

const int MAX_N = 1e5 + 5;

vii tree[MAX_N];
int deg[MAX_N];

bitset<MAX_N> visited;

pii DfsFar(int node, int parent, int d) {
    visited[node] = true;
    pii p = {d, node};
    for (auto [neighbor, w] : tree[node]) {
        if (neighbor != parent) {
            chkmax(p, DfsFar(neighbor, node, d + w));
        }
    }
    return p;
}

bool DfsPath(int node, int parent, int end, vii &path) {
    if (node == end) {
        path.push_back({node, 0});
        return true;
    }
    for (auto [neighbor, w] : tree[node]) {
        if (neighbor != parent && DfsPath(neighbor, node, end, path)) {
            path.push_back({node, w});
            return true;
        }
    }
}

int ans = 0;

int FindRadius(int node) {
    int v = DfsFar(node, -1, 0).y;
    auto [diameter, u] = DfsFar(v, -1, 0);
    int x = diameter;
    int dist = 0;
    vii path;
    DfsPath(v, -1, u, path);
    for (auto [node, w] : path) {
        chkmin(x, max(dist, diameter - dist));
        dist += w;
    }
    chkmax(ans, diameter);
    return x;
}

int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
    for (int i = 0; i < m; i++) {
        deg[a[i]]++, deg[b[i]]++;
    }
    for (int i = 0; i < n; i++) {
        tree[i].reserve(deg[i]);
    }
    for (int i = 0; i < m; i++) {
        tree[a[i]].push_back({b[i], t[i]});
        tree[b[i]].push_back({a[i], t[i]});
    }
    int s = 0;
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            s += FindRadius(i) + l;
        }
    }
    chkmax(ans, s - l);
    return ans;
}

Compilation message

dreaming.cpp: In function 'bool DfsPath(int, int, int, vii&)':
dreaming.cpp:44:1: warning: control reaches end of non-void function [-Wreturn-type]
   44 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 15236 KB Output is correct
2 Correct 48 ms 15164 KB Output is correct
3 Correct 29 ms 10728 KB Output is correct
4 Correct 7 ms 4520 KB Output is correct
5 Correct 6 ms 3544 KB Output is correct
6 Correct 10 ms 5432 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 19 ms 6836 KB Output is correct
9 Correct 28 ms 8692 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 37 ms 10316 KB Output is correct
12 Correct 43 ms 12940 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 15236 KB Output is correct
2 Correct 48 ms 15164 KB Output is correct
3 Correct 29 ms 10728 KB Output is correct
4 Correct 7 ms 4520 KB Output is correct
5 Correct 6 ms 3544 KB Output is correct
6 Correct 10 ms 5432 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 19 ms 6836 KB Output is correct
9 Correct 28 ms 8692 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 37 ms 10316 KB Output is correct
12 Correct 43 ms 12940 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Runtime error 34 ms 65536 KB Execution killed with signal 9
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 5356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 15236 KB Output is correct
2 Correct 48 ms 15164 KB Output is correct
3 Correct 29 ms 10728 KB Output is correct
4 Correct 7 ms 4520 KB Output is correct
5 Correct 6 ms 3544 KB Output is correct
6 Correct 10 ms 5432 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 19 ms 6836 KB Output is correct
9 Correct 28 ms 8692 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 37 ms 10316 KB Output is correct
12 Correct 43 ms 12940 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Runtime error 34 ms 65536 KB Execution killed with signal 9
15 Halted 0 ms 0 KB -