Submission #666075

# Submission time Handle Problem Language Result Execution time Memory
666075 2022-11-27T15:16:59 Z chanhchuong123 Crocodile's Underground City (IOI11_crocodile) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
#define task "C"
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

const long long INF = 2e18;
const int MAXN = 1e5 + 4;
int n, m, k;
int Exit[MAXN];
bool isExit[MAXN];
vector<pair<int, int>> adj[MAXN];

// subtask1-----------------------------------------------
long long f_sub1[MAXN];

long long dfs_sub1(int u, int p) {
    long long &ans = f_sub1[u];
    if (ans != INF) return ans;
    if (isExit[u]) return ans = 0;

    vector<long long> store;
    for (pair<int, int> x: adj[u]) if (x.fi != p) {
        int v = x.fi, w = x.se; dfs_sub1(v, u);
        store.push_back(f_sub1[v] + w);
    }

    sort(all(store));
    return ans = store[1];
}

long long subtask1() {
    for (int i = 0; i < n; i++) f_sub1[i] = INF;
    return dfs_sub1(0, 0);
}
//--------------------------------------------------------

// subtask23----------------------------------------------
long long d[MAXN][2];
struct node {
    long long du;
    int u;
    bool operator< (const node &other) const {
        return du > other.du;
    }
};
priority_queue<node> pq;

long long subtask23() {
    for (int i = 0; i < n; i++) d[i][0] = d[i][1] = INF;
    for (int i = 0; i < k; i++) {
        d[Exit[i]][0] = 0;
        pq.push({0, Exit[i]});
    }
    while (pq.size()) {
        long long du = pq.top().du;
        int u = pq.top().u;
        int type = du != 0;
        pq.pop();
        if (d[u][type] != du) continue;

        for (pair<int, int> x: adj[u]) {
            int v = x.fi, w = x.se;
            if (d[v][0] > du + w) {
                if (mini(d[v][1], d[v][0]))
                    pq.push({d[v][1], v});
                d[v][0] = du + w;
                pq.push({d[v][0], v});
            } else if (d[v][1] > du + w) {
                d[v][1] = du + w;
                pq.push({d[v][1], v});
            }
        }
    }
    return d[0][1];
}
//--------------------------------------------------------

long long travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
    for (int i = 0; i < m; i++) {
        int u = r[i][0], v = r[i][1], w = l[i];
        adj[u].push_back(make_pair(v, w));
        adj[v].push_back(make_pair(u, w));
    }
    for (int i = 0; i < k; i++) {
        int pos = p[i];
        Exit[i] = pos;
        isExit[pos] = true;
    }
    if (m == n - 1) return subtask1();
    else return subtask23();
}

Compilation message

crocodile.cpp:89:11: error: ambiguating new declaration of 'long long int travel_plan(int, int, int (*)[2], int*, int, int*)'
   89 | long long travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
      |           ^~~~~~~~~~~
In file included from crocodile.cpp:2:
crocodile.h:1:5: note: old declaration 'int travel_plan(int, int, int (*)[2], int*, int, int*)'
    1 | int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]);
      |     ^~~~~~~~~~~