Submission #1073978

# Submission time Handle Problem Language Result Execution time Memory
1073978 2024-08-25T05:45:48 Z Ignut Dreaming (IOI13_dreaming) C++17
0 / 100
78 ms 14284 KB
// Ignut

#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;
using ll = long long;

const int INF = 1e9 + 123;
const int MAXN = 1e5 + 123;

vector<pair<int, int>> tree[MAXN];
int dist[MAXN];

void dfs(int v, int par, int d) {
    dist[v] = d;
    for (auto [to, w] : tree[v])
        if (to != par)
            dfs(to, v, d + w); 
}

void FindDist(int source) {
    dfs(source, -1, 0);
}

bool used[MAXN];
vector<int> comp;

void dfs0(int v, int par = -1) {
    used[v] = true;
    comp.push_back(v);
    for (auto [to, w] : tree[v])
        if (to != par)
            dfs0(to, v);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for (int i = 0; i < N; i ++) {
        tree[i].clear();
        used[i] = false;
    }
    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]});
    }
    
    vector<int> c;
    for (int i = 0; i < N; i ++) {
        if (used[i]) continue;
        comp.clear();
        dfs0(i);
        FindDist(i);
        map<int, int> d1;
        for (int v : comp) d1[v] = dist[v];
        int j = i;
        for (int v : comp) if (dist[v] > dist[j]) j = v;
        FindDist(j);

        int ctr = i, maxDist = INF;
        for (int v : comp) {
            int d = max(d1[v], dist[v]);
            if (d < maxDist) {
                ctr = v;
                maxDist = d;
            }
        }
        c.push_back(ctr);
    }

    if (c.size() == 2) {
        tree[c[0]].push_back({c[1], L});
        tree[c[1]].push_back({c[0], L});
    }

    int res = 0;
    FindDist(0);
    int j = 0;
    for (int i = 0; i < N; i ++) if (dist[i] > dist[j]) j = i;
    FindDist(j);
    for (int i = 0; i < N; i ++) res = max(res, dist[i]);
    return res;
}

# Verdict Execution time Memory Grader output
1 Correct 77 ms 14184 KB Output is correct
2 Correct 78 ms 14284 KB Output is correct
3 Correct 47 ms 10960 KB Output is correct
4 Correct 9 ms 4440 KB Output is correct
5 Correct 8 ms 3728 KB Output is correct
6 Correct 16 ms 5320 KB Output is correct
7 Incorrect 2 ms 2652 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Incorrect 1 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 14184 KB Output is correct
2 Correct 78 ms 14284 KB Output is correct
3 Correct 47 ms 10960 KB Output is correct
4 Correct 9 ms 4440 KB Output is correct
5 Correct 8 ms 3728 KB Output is correct
6 Correct 16 ms 5320 KB Output is correct
7 Incorrect 2 ms 2652 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 5980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Incorrect 1 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 14184 KB Output is correct
2 Correct 78 ms 14284 KB Output is correct
3 Correct 47 ms 10960 KB Output is correct
4 Correct 9 ms 4440 KB Output is correct
5 Correct 8 ms 3728 KB Output is correct
6 Correct 16 ms 5320 KB Output is correct
7 Incorrect 2 ms 2652 KB Output isn't correct
8 Halted 0 ms 0 KB -