Submission #844751

# Submission time Handle Problem Language Result Execution time Memory
844751 2023-09-05T19:43:05 Z detaomega Dreaming (IOI13_dreaming) C++14
0 / 100
16 ms 2648 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
#include "dreaming.h"

const int maxn = 1e3 + 5;

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

int getDiameter(int n) {
    queue<int> q;
    vector<int> dis(maxn, -1);
    q.push(1);
    dis[1] = 0;
    while (q.size()) {
        int u = q.front();
        q.pop();
        for (auto e : G[u]) {
            int v = e.first;
            if (dis[v] == -1) {
                dis[v] = dis[u] + e.second;
                q.push(v);
            }
        }
    }
    int now = 0, mx = 0;
    for (int i = 1; i <= n; i++) {
        if (mx < dis[i]) {
            mx = dis[i];
            now = i;
        }
        dis[i] = -1;
    }
    q.push(now);
    dis[now] = 0;
    while (q.size()) {
        int u = q.front();
        q.pop();
        for (auto e : G[u]) {
            int v = e.first;
            if (dis[v] == -1) {
                dis[v] = dis[u] + e.second;
                q.push(v);
            }
        }
    }
    return *max_element(dis.begin(), dis.end());
}
vector<int> dp(maxn, 0);
vector<int> in(maxn, 0);
vector<int> vis(maxn, 0);

int dfs(int now, int fa) {
    int mx = dp[now];
    vis[now] = true;
    for (auto e : G[now]) {
        int v = e.first;
        if (v == fa) {
            continue;
        }
        mx = max(mx, dfs(v, now));
    }
    return mx;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for (int i = 0; i < M; i++) {
        // cout << A[i] << " " << B[i];
        G[++A[i]].emplace_back(++B[i], T[i]);
    }
    if (N == 1) {
        return 0;
    }
    if (N == M + 1) {
        return getDiameter(N);
    }
    if (N == 2) {
        return L;
    }
    if (M == 0) {
        return L * 2;
    }
    queue<int> q;
    for (int i = 1; i <= N; i++) {
        if (G[i].size() == 1) {
            q.push(i);
        }
        in[i] = G[i].size();
    }
    while (q.size()) {
        int u = q.front();
        q.pop();
        in[u] = 0;
        for (auto e : G[u]) {
            int v = e.first;
            dp[v] = max(dp[v], dp[u] + e.second);
            in[v]--;
            if (in[v] == 1) {
                q.push(v);
            }   
        }
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (!vis[i]) {
            ans = ans + dfs(i, 0);
        }
    }
    return ans + L;
}
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 2648 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 2648 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1200 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 2648 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -