Submission #482053

# Submission time Handle Problem Language Result Execution time Memory
482053 2021-10-22T18:48:20 Z bill_lin Crocodile's Underground City (IOI11_crocodile) C++14
100 / 100
759 ms 100800 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
 
const ll INF = 1e15;
vector<vector<pll>> adj;

int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]) {
    vector<ll> dist(n, INF);
    adj.resize(n);
    for (int i = 0; i < m; i++) {
        adj[R[i][0]].push_back({L[i], R[i][1]});
        adj[R[i][1]].push_back({L[i], R[i][0]});
    }
    
    for (int i = 0; i < n; i++) sort(adj[i].begin(), adj[i].end());
    
    vector<bool> can(n, false);
    priority_queue<pll, vector<pll>, greater<pll>> q;
    for (int i = 0; i < k; i++) {
        q.push({0, P[i]});
        can[P[i]] = true;
    }
    
    while (!q.empty()) {
        auto p = q.top();
        q.pop();
        ll curr_cost = p.first, node = p.second;
        
        if (can[node] && curr_cost >= dist[node]) continue;
        if (!can[node]) {
            can[node] = true;
            continue;
        }
        dist[node] = curr_cost;
        for (int i = 0; i < adj[node].size(); i++) {
            ll edge_cost = adj[node][i].first, dest = adj[node][i].second;
            if (curr_cost + edge_cost < dist[dest]) {
//                dist[dest] = curr_cost + edge_cost;
                q.push({curr_cost + edge_cost, dest});
            }
        }
    }
    
    return dist[0];
    
}
//int32_t main() {
//    ios_base::sync_with_stdio(false);
//    cin.tie(nullptr);
//
////    int n = 5, m = 7, k = 2;
////    int R[][2] = {{0, 2}, {0, 3}, {3, 2}, {2, 1}, {0, 1}, {0, 4}, {3, 4}};
////    int L[] = {4, 3, 2, 10, 100, 7, 9};
////    int P[] = {1, 3};
//
////    int n = 5, m = 4, k = 3;
////    int R[][2] = {{0, 1}, {0, 2}, {3, 2}, {2, 4}};
////    int L[] = {2, 3, 1, 4};
////    int P[] = {1, 3, 4};
//
////    cout << travel_plan(n, m, R, L, k, P);
//
//    int n, m, k;
//    cin >> n >> m >> k;
//
//    int R[m][2], L[m], P[k];
//    for (int i = 0; i < m; i++) {
//        int u, v, cost;
//        cin >> u >> v >> cost;
//        R[i][0] = u, R[i][1] = v;
//        L[i] = cost;
//    }
//    for (int i = 0; i < k; i++) {
//        cin >> P[i];
//    }
//
//    cout << travel_plan(n, m, R, L, k, P) << '\n';
//}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:39:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for (int i = 0; i < adj[node].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 844 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 5 ms 1356 KB Output is correct
13 Correct 7 ms 1484 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 844 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 5 ms 1356 KB Output is correct
13 Correct 7 ms 1484 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 668 ms 95484 KB Output is correct
17 Correct 82 ms 16836 KB Output is correct
18 Correct 95 ms 19220 KB Output is correct
19 Correct 759 ms 100800 KB Output is correct
20 Correct 540 ms 82160 KB Output is correct
21 Correct 36 ms 7772 KB Output is correct
22 Correct 499 ms 62784 KB Output is correct