Submission #544299

# Submission time Handle Problem Language Result Execution time Memory
544299 2022-04-01T15:40:00 Z Jomnoi Dreaming (IOI13_dreaming) C++17
0 / 100
1000 ms 17740 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;

const int MAX = 1e5 + 10;

vector <pair <int, int>> adj[MAX];
pair <int, int> ma[MAX][2];
bool visited[MAX];

template <typename T>
void upd(T *ma, T x) {
    if(ma[0] < x) {
        swap(ma[0], x);
    }
    if(ma[1] < x) {
        swap(ma[1], x);
    }
}

void dfs(int u, int p) {
    for(auto [v, w] : adj[u]) {
        if(v == p) {
            continue;
        }

        dfs(v, u);
        upd(ma[u], make_pair(ma[v][0].first + w, v));
    }
}

int dfs2(int u, int p, int pw) {
    int res = ma[u][0].first + pw;
    for(auto [v, w] : adj[u]) {
        if(v == p) {
            continue;
        }

        int nw = pw + w;
        if(ma[u][0].second == v) {
            nw += ma[u][1].first;
        }
        else {
            nw += ma[u][0].first;
        }

        res = min(res, dfs2(v, u, nw));
    }
    return res;
}

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

    for(int i = 1; i <= N; i++) {
        ma[i][0] = make_pair(0, -1);
        ma[i][1] = make_pair(0, -1);
    }
    for(int i = 1; i <= N; i++) {
        if(ma[i][0].second == -1) {
            dfs(i, -1);
        }
    }
    
    int max_dist[2] = {-1, -1};
    for(int i = 1; i <= N; i++) {
        if(visited[i] == false) {
            visited[i] = true;
            upd(max_dist, dfs2(i, -1, 0));
        }
    }

    if(max_dist[1] == -1) {
        return max_dist[0] + L;
    }
    return max_dist[0] + max_dist[1] + 2 * L;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 17740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 17740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 6928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 17740 KB Time limit exceeded
2 Halted 0 ms 0 KB -