Submission #337298

# Submission time Handle Problem Language Result Execution time Memory
337298 2020-12-19T13:33:39 Z r_v_n Crocodile's Underground City (IOI11_crocodile) C++14
Compilation error
0 ms 0 KB
using namespace std;
#include <bits/stdc++.h>
#define ll long long
int dp[100001];
int n;
int m, k;
vector<pair<int, int>> adj[100001];
map<int, int> is;
void dfs(int v, int p = -1)
{
    if (adj[v].size() == 1)
    {
        if (is[v])
            dp[v] = 0;
        else
            dp[v] = 1e9;
        return;
    }
    vector<int> store;
    for (auto it : adj[v])
    {
        if (it.first == p)
            continue;
        dfs(it.first, v);
        store.push_back(dp[it.first] + it.second);
    }
    sort(store.begin(), store.end());
    dp[v] = store[1];
}
// void solve()
// {
//     cin >> n >> m >> k;
//     for (int i = 0; i <= n; i++)
//     {
//         adj[i].clear();
//         dp[i] = 0;
//     }
//     is.clear();
//     for (int i = 0; i < m; i++)
//     {
//         int a, b, c;
//         cin >> a >> b >> c;
//         adj[a].push_back({b, c});
//         adj[b].push_back({a, c});
//     }
//     for (int i = 0; i < k; i++)
//     {
//         int a;
//         cin >> a;
//         is[a] = 1;
//     }
//     dfs(0);
//     cout << dp[0] << endl;
// }
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    for (int i = 0; i < M; i++)
    {
        adj[R[i][0]].push_back(make_pair(R[i][1], L[i]));
        adj[R[i][1]].push_back(make_pair(R[i][0], L[i]));
    }
    map<int, int> f;
    vector<int> d(n + 1, 1e9);
    vector<int> visited(n + 1, 0);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    for (int i = 0; i < K; i++)
    {
        //is[P[i]] = 1;
        q.push({0, P[i]});
        visited[P[i]] = 1;
    }
    while (!pq.empty())
    {
        int u = q.top().second;
        int cost = q.top().first;
        q.pop();
        if (visited[u] == 1)
        {
            is[u] = 1;
            d[u] = cost;
            for (int i = 0; i < adj[u].size(); i++)
            {
                int v = adj[u][i].ff;
                int cst = adj[u][i].ss;
                if (!is[v])
                    q.push(make_pair((cost + cst), v));
            }
        }
        viz[u]++;
    }
    return d[0];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:72:13: error: 'pq' was not declared in this scope; did you mean 'q'?
   72 |     while (!pq.empty())
      |             ^~
      |             q
crocodile.cpp:81:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |             for (int i = 0; i < adj[u].size(); i++)
      |                             ~~^~~~~~~~~~~~~~~
crocodile.cpp:83:35: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'ff'
   83 |                 int v = adj[u][i].ff;
      |                                   ^~
crocodile.cpp:84:37: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'ss'
   84 |                 int cst = adj[u][i].ss;
      |                                     ^~
crocodile.cpp:89:9: error: 'viz' was not declared in this scope
   89 |         viz[u]++;
      |         ^~~