Submission #655263

# Submission time Handle Problem Language Result Execution time Memory
655263 2022-11-03T16:14:11 Z happypotato Dreaming (IOI13_dreaming) C++17
18 / 100
48 ms 13904 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
const int mxN = 1e5 + 1;
vector<pii> adj[mxN];
bool vis[mxN];
int dist[mxN], dist2[mxN];
pii dfs(int u, int par = -1) {
    vis[u] = true;
    pii res = {u, 0};
    for (pii &v : adj[u]) {
        if (v.ff != par) {
            pii ret = dfs(v.ff, u);
            ret.ss += v.ss;
            if (ret.ss > res.ss) {
                res = ret;
            }
        }
    }
    return res;
}
int FindRadii(int lhs, int rhs) {
    if (lhs == rhs) return 0;
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    vector<int> nodes;
    // from lhs
    pq.push({lhs, 0});
    dist[lhs] = 0;
    nodes.pb(lhs);
    while (!pq.empty()) {
        pii cur = pq.top();
        pq.pop();
        if (cur.ss > dist[cur.ff]) continue;
        nodes.pb(cur.ff);
        for (pii &v : adj[cur.ff]) {
            if (dist[v.ff] > cur.ss + v.ss) {
                dist[v.ff] = cur.ss + v.ss;
                pq.push({v.ff, dist[v.ff]});
            }
        }
    }
    // from rhs
    pq.push({rhs, 0});
    dist2[rhs] = 0;
    while (!pq.empty()) {
        pii cur = pq.top();
        pq.pop();
        if (cur.ss > dist2[cur.ff]) continue;
        for (pii &v : adj[cur.ff]) {
            if (dist2[v.ff] > cur.ss + v.ss) {
                dist2[v.ff] = cur.ss + v.ss;
                pq.push({v.ff, dist2[v.ff]});
            }
        }
    }
    int ans = 2e9;
    for (int &x : nodes) {
        ans = min(ans, max(dist[x], dist2[x]));
    }
    return ans;
}
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]].pb({B[i], T[i]});
        adj[B[i]].pb({A[i], T[i]});
    }
    for (int i = 1; i <= n; i++) {
        dist[i] = dist2[i] = 2e9;
    }
    vector<int> fin;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            pii lhs = dfs(i);
            pii rhs = dfs(lhs.ff);
            fin.pb(FindRadii(lhs.ff, rhs.ff));
        }
    }
    sort(fin.begin(), fin.end(), greater<int>());
    if (fin.size() == 1) return fin[0];
    else if (fin.size() == 2) return fin[0] + fin[1] + L;
    else return max(fin[0] + fin[1] + L, fin[1] + fin[2] + L * 2);
}
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 13904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 13904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 6412 KB Output is correct
2 Correct 31 ms 6436 KB Output is correct
3 Correct 34 ms 6472 KB Output is correct
4 Correct 26 ms 6484 KB Output is correct
5 Correct 24 ms 6356 KB Output is correct
6 Correct 25 ms 6828 KB Output is correct
7 Correct 29 ms 6612 KB Output is correct
8 Correct 26 ms 6356 KB Output is correct
9 Correct 23 ms 6288 KB Output is correct
10 Correct 28 ms 6480 KB Output is correct
11 Correct 2 ms 2656 KB Output is correct
12 Correct 5 ms 4180 KB Output is correct
13 Correct 5 ms 4176 KB Output is correct
14 Correct 5 ms 4136 KB Output is correct
15 Correct 4 ms 4176 KB Output is correct
16 Correct 5 ms 4176 KB Output is correct
17 Correct 5 ms 4176 KB Output is correct
18 Correct 5 ms 4176 KB Output is correct
19 Correct 4 ms 4176 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 5 ms 4176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 13904 KB Output isn't correct
2 Halted 0 ms 0 KB -