답안 #743942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
743942 2023-05-18T06:28:51 Z josanneo22 악어의 지하 도시 (IOI11_crocodile) C++17
100 / 100
443 ms 45296 KB
#include <bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
using namespace std;

#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second  

const int mxn = 1e5;
const int inf = 1e9 + 3;
vector<pii>adj[mxn + 1];
pii d[mxn + 1];
struct ch {
    int u, d;
};
struct cmp {
    bool operator()(ch a, ch b) {
        return(a.d > b.d);
    }
};
/*
    from subtask 1: only the second answer matters
    do djikstra from each of the exit nodes 
    by sorting ascending values of the second answer
*/
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
    for (int i = 0; i < n; i++) {
        d[i].fi = d[i].se = inf;
    }
    for (int i = 0; i < m; i++) {
        int u = r[i][0], v = r[i][1], w = l[i];
        adj[u].pb({ v, w }); adj[v].pb({ u, w });
    }
    priority_queue<ch, vector<ch>, cmp>pq;
    //first is index, second is weight accumlated
    for (int i = 0; i < k; i++) {
        d[p[i]].fi = d[p[i]].se = 0;
        pq.push({ p[i], 0 });
    }
    while (!pq.empty()) {
        ch nw = pq.top(); pq.pop();
        int u = nw.u, dd = nw.d;
        if (u == 0) {
            return (dd);
        }
        if (d[u].se < dd)continue;
        for (auto i : adj[u]) {
            int v = i.fi, w = i.se;
            if (dd + w < d[v].se) {
                int cr = d[v].se;
                d[v].se = dd + w;
                if (d[v].fi > d[v].se) swap(d[v].fi, d[v].se);//remember to swap
                if (d[v].se < cr) {//if there is a change
                    pq.push({ v, d[v].se });
                }
            }
        }
    }
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:38:40: warning: control reaches end of non-void function [-Wreturn-type]
   38 |     priority_queue<ch, vector<ch>, cmp>pq;
      |                                        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 6 ms 3156 KB Output is correct
13 Correct 5 ms 3168 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 3 ms 2676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 6 ms 3156 KB Output is correct
13 Correct 5 ms 3168 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 3 ms 2676 KB Output is correct
16 Correct 382 ms 41572 KB Output is correct
17 Correct 61 ms 10652 KB Output is correct
18 Correct 71 ms 11976 KB Output is correct
19 Correct 443 ms 45296 KB Output is correct
20 Correct 285 ms 37052 KB Output is correct
21 Correct 43 ms 6440 KB Output is correct
22 Correct 255 ms 32240 KB Output is correct