답안 #717598

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
717598 2023-04-02T09:14:36 Z hafo 악어의 지하 도시 (IOI11_crocodile) C++14
컴파일 오류
0 ms 0 KB
#include "crocodile.h"
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}

const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 7;
const ll oo = 1e17 + 69;

int n, m, r[maxn][2], l[maxn], k, p[maxn];
ll f[maxn][2];
int trace[maxn][2];
vector<pa> g[maxn];

int travel_plan() {
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
    memset(f, 0x3f, sizeof f);
    memset(trace, -1, sizeof trace);
    for(int i = 0; i < k; i++) {
        f[p[i]][0] = 0;
        q.push({0, p[i]});
    }

    for(int i = 0; i < m; i++) {
        int u = r[i][0], v = r[i][1];
        g[u].push_back({v, l[i]});
        g[v].push_back({u, l[i]});
    }

    while(!q.empty()) {
        int u = q.top().second;
        long long fu = q.top().first;
        q.pop();

        if(fu > f[u][1]) continue;
        for(auto e:g[u]) {
            int v = e.first, w = e.second;
            if(f[v][0] == 0) continue;
            if(trace[u][0] == v || trace[u][1] == v) continue;
            if(f[v][0] > fu + w) {
                f[v][1] = f[v][0];
                trace[v][1] = trace[v][0];
                f[v][0] = fu + w;
                trace[v][0] = u;
                q.push({fu + w, v});
            } else if(f[v][1] > fu + w) {
                f[v][1] = fu + w;
                trace[v][1] = u;
                q.push({fu + w, v});
            }
        }
    }

    int res = 0, u = 0;
    vector<int> path;
    while(trace[u][1] != -1) {
        path.pb(u);
        u = trace[u][1];
    }
    path.pb(u);
    for(int i = 0; i < (int) path.size() - 1; i++) {
        int u = path[i], v = path[i + 1];
        for(auto e:g[u]) {
            if(e.first == v) res += e.second;
        }
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //freopen(TASK".inp", "r", stdin);
    //freopen(TASK".out", "w", stdout);

    cin>>n>>m;
    for(int i = 0; i < m; i++) cin>>r[i][0]>>r[i][1];
    for(int i = 0; i < m; i++) cin>>l[i];
    cin>>k;
    for(int i = 0; i < k; i++) cin>>p[i];
    cout<<travel_plan();
    return 0;
}

Compilation message

/usr/bin/ld: /tmp/cc41mEgC.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cchEWzHC.o:crocodile.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc41mEgC.o: in function `main':
grader.cpp:(.text.startup+0x36): undefined reference to `travel_plan(int, int, int (*) [2], int*, int, int*)'
collect2: error: ld returned 1 exit status