답안 #655261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
655261 2022-11-03T16:10:45 Z happypotato 꿈 (IOI13_dreaming) C++17
18 / 100
59 ms 14976 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) {
    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);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 14976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 14976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 6596 KB Output is correct
2 Correct 42 ms 6624 KB Output is correct
3 Correct 28 ms 6628 KB Output is correct
4 Correct 33 ms 6580 KB Output is correct
5 Correct 32 ms 6620 KB Output is correct
6 Correct 35 ms 6992 KB Output is correct
7 Correct 30 ms 6780 KB Output is correct
8 Correct 29 ms 6480 KB Output is correct
9 Correct 31 ms 6488 KB Output is correct
10 Correct 32 ms 6700 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 14 ms 4192 KB Output is correct
13 Correct 13 ms 4176 KB Output is correct
14 Correct 15 ms 4176 KB Output is correct
15 Correct 14 ms 4196 KB Output is correct
16 Correct 15 ms 4192 KB Output is correct
17 Correct 19 ms 4136 KB Output is correct
18 Correct 15 ms 4192 KB Output is correct
19 Correct 14 ms 4176 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2664 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 20 ms 4128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 14976 KB Output isn't correct
2 Halted 0 ms 0 KB -