Submission #666091

# Submission time Handle Problem Language Result Execution time Memory
666091 2022-11-27T15:26:09 Z chanhchuong123 Crocodile's Underground City (IOI11_crocodile) C++14
0 / 100
5 ms 5208 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 int MAXN = 1e5 + 4;
const int INF = 1e9 + 7;
int n, m, k;
int Exit[MAXN];
bool isExit[MAXN];
vector<pair<int, int>> adj[MAXN];

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

int dfs_sub1(int u, int p) {
    int &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];
}

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

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

int 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;
        d[Exit[i]][1] = 0;
        pq.push({0, Exit[i]});
    }
    while (pq.size()) {
        int du = pq.top().du;
        int u = pq.top().u;
        int type = du != 0;
        pq.pop();
        if (u == 0) return du;

        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;
            } else if (d[v][1] > du + w) {
                d[v][1] = du + w;
                pq.push({d[v][1], v});
            }
        }
    }
}
//--------------------------------------------------------

int 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;
    }
    return subtask23();
}

Compilation message

crocodile.cpp: In function 'int subtask23()':
crocodile.cpp:68:13: warning: unused variable 'type' [-Wunused-variable]
   68 |         int type = du != 0;
      |             ^~~~
crocodile.cpp:84:1: warning: control reaches end of non-void function [-Wreturn-type]
   84 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5208 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5208 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5208 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -