Submission #385307

# Submission time Handle Problem Language Result Execution time Memory
385307 2021-04-04T04:01:06 Z ngpin04 Crocodile's Underground City (IOI11_crocodile) C++14
100 / 100
565 ms 45288 KB
#include <bits/stdc++.h>
#include "crocodile.h"
//#include "crocodile.cpp"
//#include "grader.cpp"
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int NN = 1e5 + 5;
const int oo = 1e9 + 1;

vector <pair <int, int>> adj[NN];

int dis[NN][3];
int n;

bool vis[NN];

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];
        int v = r[i][1];
        int w = l[i];
        adj[u].push_back(mp(v, w));
        adj[v].push_back(mp(u, w));
    }
    for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++)
        dis[i][j] = oo;

    priority_queue <pair <int, int>> heap;

    for (int i = 0; i < k; i++)
    for (int j = 0; j < 2; j++) {
        dis[p[i]][j] = 0;
        if (j == 1)
            heap.push(mp(0, p[i]));
    }
    while (heap.size()) {
        int u = heap.top().se;
        int cur = -heap.top().fi;
        heap.pop();
        if (dis[u][1] != cur)
            continue;
        for (pair <int, int> e : adj[u]) {
            int v = e.fi;
            int w = e.se;
            bool ok = false;
            dis[v][2] = cur + w;
            int tmp = dis[v][1];
            for (int i = 2; i >= 1; i--)
                if (dis[v][i] < dis[v][i - 1])
                    swap(dis[v][i], dis[v][i - 1]);
            if (tmp != dis[v][1])
                heap.push(mp(-dis[v][1], v));
            //if (v == 0){
                //cerr << u << " " << v << " " << w << endl;
                //for (int i = 0; i < 3; i++)
                //    cerr << dis[0][i] << " ";
                //cerr << endl;
            //}
        }
    }
    return dis[0][1];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:49:18: warning: unused variable 'ok' [-Wunused-variable]
   49 |             bool ok = false;
      |                  ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2796 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 3 ms 2796 KB Output is correct
8 Correct 3 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2796 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 3 ms 2796 KB Output is correct
8 Correct 3 ms 2796 KB Output is correct
9 Correct 5 ms 2924 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 4 ms 2796 KB Output is correct
12 Correct 6 ms 3052 KB Output is correct
13 Correct 5 ms 3180 KB Output is correct
14 Correct 3 ms 2668 KB Output is correct
15 Correct 3 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2796 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 3 ms 2796 KB Output is correct
8 Correct 3 ms 2796 KB Output is correct
9 Correct 5 ms 2924 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 4 ms 2796 KB Output is correct
12 Correct 6 ms 3052 KB Output is correct
13 Correct 5 ms 3180 KB Output is correct
14 Correct 3 ms 2668 KB Output is correct
15 Correct 3 ms 2796 KB Output is correct
16 Correct 468 ms 41572 KB Output is correct
17 Correct 77 ms 10860 KB Output is correct
18 Correct 97 ms 12268 KB Output is correct
19 Correct 565 ms 45288 KB Output is correct
20 Correct 334 ms 36588 KB Output is correct
21 Correct 40 ms 6380 KB Output is correct
22 Correct 327 ms 32108 KB Output is correct