답안 #1025789

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025789 2024-07-17T10:08:15 Z onbert 꿈 (IOI13_dreaming) C++17
0 / 100
33 ms 15304 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 5, INF = 1e18;
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;
    // cout << "u " << u << endl;
    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 ans = l;
    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) cout << j << " "; cout << endl;
        for (int j:cur) if (dist[j] > dist[finish]) finish = j;
        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 ans;
}

// 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;
// }
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 15304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 15304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 15304 KB Output isn't correct
2 Halted 0 ms 0 KB -