Submission #482052

# Submission time Handle Problem Language Result Execution time Memory
482052 2021-10-22T18:40:09 Z bill_lin Crocodile's Underground City (IOI11_crocodile) C++14
Compilation error
0 ms 0 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);
}

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++) {
      |                         ~~^~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccXW21Md.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cciaSZof.o:crocodile.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status