제출 #1207816

#제출 시각아이디문제언어결과실행 시간메모리
1207816orcslop꿈 (IOI13_dreaming)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 0
#define dbgn(...) 0
#endif

const int INF = 1e9; 

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, m, l; 
    cin >> n >> m >> l; 
    vector<vector<pair<int, int>>> adj(n); 
    for(int i = 0; i < m; i++){
        int a, b, t; 
        cin >> a >> b >> t; 
        adj[a].push_back({b, t}); 
        adj[b].push_back({a, t}); 
    }
    vector<int> cc_time; 
    auto dijkstra = [&](int start_node) {
        vector<int> dist(n, INF);
        if (start_node >= 0 && start_node < n) {
            dist[start_node] = 0;
            // Priority queue stores {distance, node}, ordered by the smallest distance
            priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
            pq.push({0, start_node});
            while (!pq.empty()) {
                int d = pq.top().first;
                int u = pq.top().second;
                pq.pop();
                if (d > dist[u]) continue; 
                for (auto& edge : adj[u]) {
                    int v = edge.first;
                    int weight = edge.second;
                    if (dist[u] + weight < dist[v]) {
                        dist[v] = dist[u] + weight;
                        pq.push({dist[v], v});
                    }
                }
            }
        }
        return dist;
    };
    vector<bool> vis(n, false);
    for (int i = 0; i < n; ++i) {
        if (!vis[i]) {
            vector<int> ccn;
            queue<int> q;
            q.push(i);
            vis[i] = true;
            while (!q.empty()) {
                int u = q.front();
                q.pop();
                ccn.push_back(u);
                for (auto& edge : adj[u]) {
                    int v = edge.first;
                    if (!vis[v]) {
                        vis[v] = true;
                        q.push(v);
                    }
                }
            }
            if (ccn.size() <= 1) {
                cc_time.push_back(0);
                continue;
            }
            int snfd = i;
            vector<int> st_dist = dijkstra(snfd);

            int endpoint_a = -1;
            int max_dist = -1;
            for (int node : ccn) {
                if (st_dist[node] != INF && st_dist[node] > max_dist) {
                    max_dist = st_dist[node];
                    endpoint_a = node;
                }
            }
            vector<int> a_dist = dijkstra(endpoint_a);
            int endpoint_b = -1;
            max_dist = -1;
            for (int node : ccn) {
                if (a_dist[node] != INF && a_dist[node] > max_dist) {
                    max_dist = a_dist[node];
                    endpoint_b = node;
                }
            }
            vector<int> b_dist = dijkstra(endpoint_b);
            int c = INF;
            for (int node : ccn) {
                int e = max(a_dist[node], b_dist[node]);
                if (e < c) {
                    c = e;
                }
            }
            cc_time.push_back(c);
        }
    }
    sort(cc_time.begin(), cc_time.end(), greater()); 
    int ans = cc_time[0]; 
    if(cc_time.size() >= 2) ans = max(ans, cc_time[0] + cc_time[1] + l); 
    if(cc_time.size() >= 3) ans = max(ans, cc_time[1] + cc_time[2] + 2 * l); 
    cout << ans << '\n'; 
    return 0; 
}

컴파일 시 표준 에러 (stderr) 메시지

/usr/bin/ld: /tmp/ccAjN3nS.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/cc5c2oq4.o:dreaming.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccAjN3nS.o: in function `main':
grader.c:(.text.startup+0xc4): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status