Submission #1025914

# Submission time Handle Problem Language Result Execution time Memory
1025914 2024-07-17T11:11:23 Z onbert Dreaming (IOI13_dreaming) C++17
14 / 100
32 ms 13008 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5, INF = 1e9;
int n, m, l;
vector<pair<int,int>> adj[maxn];
int dist[maxn];
vector<int> cur;

void dfs(int u) {
    cur.push_back(u);
    for (auto [v, w]:adj[u]) if (dist[v] == -1) {
        dist[v] = dist[u] + w;
        dfs(v);
    }
}

int finish;
vector<int> track;
bool done;
void dfs2(int u) {
    if (!done) track.push_back(u);
    if (u==finish) done = true;
    for (auto [v, w]:adj[u]) if (dist[v] == -1) {
        dist[v] = dist[u] + w;
        dfs2(v);
    }
    if (!done) track.pop_back();
}

int32_t travelTime(int32_t N, int32_t M, int32_t L, int32_t A[], int32_t B[], int32_t T[]) {
    n = N, m = M, l = L;
    for (int i=0;i<m;i++) {
        adj[A[i]].push_back({B[i], T[i]});
        adj[B[i]].push_back({A[i], T[i]});
    }
    for (int i=0;i<n;i++) dist[i] = -1;
    int32_t ans1 = l, ans2 = 0;
    for (int i=0;i<n;i++) if (dist[i] == -1) {
        cur.clear();
        dist[i] = 0;
        dfs(i);
        int start = i;
        for (int j:cur) if (dist[j] > dist[start]) start = j;
        for (int j:cur) dist[j] = -1;
        cur.clear();
        dist[start] = 0;
        dfs(start);
        finish = start;
        for (int j:cur) if (dist[j] > dist[finish]) finish = j;
        ans2 = max(dist[finish], ans2);
        int cost = INF;
        for (int j:cur) cost = min(max(dist[j], dist[finish]-dist[j]), cost);
        ans1 += cost;
        // for (int j:cur) dist[j] = -1;
        // dist[start] = 0, done = false;
        // track.clear();
        // dfs2(start);
        // int cost = INF;
        // for (int j:track) cost = min(max(dist[finish]-dist[j], dist[j]), cost);
        // ans += cost;
    }
    return max(ans1, ans2);
}

// signed main() {
//     ios::sync_with_stdio(0); cin.tie(0);
//     int32_t n, m, l;
//     cin >> n >> m >> l;
//     int32_t a[m], b[m], t[m];
//     for (int i=0;i<m;i++) cin >> a[i] >> b[i] >> t[i];
//     cout << travelTime(n, m, l, a, b, t) << endl;
// }
# Verdict Execution time Memory Grader output
1 Correct 28 ms 11728 KB Output is correct
2 Correct 28 ms 13008 KB Output is correct
3 Correct 19 ms 10196 KB Output is correct
4 Correct 5 ms 5468 KB Output is correct
5 Correct 7 ms 4844 KB Output is correct
6 Correct 9 ms 6236 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
8 Correct 15 ms 7260 KB Output is correct
9 Correct 22 ms 8640 KB Output is correct
10 Correct 1 ms 4188 KB Output is correct
11 Correct 28 ms 10164 KB Output is correct
12 Correct 32 ms 11468 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3928 KB Output is correct
2 Correct 1 ms 3932 KB Output is correct
3 Incorrect 1 ms 3932 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 11728 KB Output is correct
2 Correct 28 ms 13008 KB Output is correct
3 Correct 19 ms 10196 KB Output is correct
4 Correct 5 ms 5468 KB Output is correct
5 Correct 7 ms 4844 KB Output is correct
6 Correct 9 ms 6236 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
8 Correct 15 ms 7260 KB Output is correct
9 Correct 22 ms 8640 KB Output is correct
10 Correct 1 ms 4188 KB Output is correct
11 Correct 28 ms 10164 KB Output is correct
12 Correct 32 ms 11468 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 1 ms 3928 KB Output is correct
15 Correct 1 ms 3932 KB Output is correct
16 Incorrect 1 ms 3932 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 6236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3928 KB Output is correct
2 Correct 1 ms 3932 KB Output is correct
3 Incorrect 1 ms 3932 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 11728 KB Output is correct
2 Correct 28 ms 13008 KB Output is correct
3 Correct 19 ms 10196 KB Output is correct
4 Correct 5 ms 5468 KB Output is correct
5 Correct 7 ms 4844 KB Output is correct
6 Correct 9 ms 6236 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
8 Correct 15 ms 7260 KB Output is correct
9 Correct 22 ms 8640 KB Output is correct
10 Correct 1 ms 4188 KB Output is correct
11 Correct 28 ms 10164 KB Output is correct
12 Correct 32 ms 11468 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 1 ms 3928 KB Output is correct
15 Correct 1 ms 3932 KB Output is correct
16 Incorrect 1 ms 3932 KB Output isn't correct
17 Halted 0 ms 0 KB -