Submission #316405

# Submission time Handle Problem Language Result Execution time Memory
316405 2020-10-26T09:22:31 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 n, m, k;
vector<pair<int, int>> adj[100001];
vector<int> dist(100001, 1e8);
vector<int> have;
vector<vector<int>> dista(100001);
void dij()
{
    vector<int> visited(n + 1, 0);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    for (auto i : have)
    {
        /// cout<<have[i]<<endl;
        // return ;
        q.push({0, i});
        dist[i] = 0;
        dista[i].push_back(0);
        visited[i]=1;
    }
    int val = 5;
    while (!q.empty())
    {
        int currnode = q.top().second;
        int curdis;
        if (dista[currnode].size() == 1)
            curdis = dista[currnode][0];
        else
            curdis = dista[currnode][1];
        // int curdis=dista[currnode][1];
        //cerr << currnode << " " << curdis << endl;
        q.pop();
        if (dista[currnode].back() < curdis)
            continue;
        for (auto it : adj[currnode])
        {
            if (dista[it.first].size() < 2)
            {
                dista[it.first].push_back(curdis + it.second);
                q.push({curdis + it.second, it.first});
                sort(dista[it.first].begin(), dista[it.first].end());
            }
            else
            {
                // decide if it is going to be added or not
                int val1 = curdis + it.second;
                if (val1 <= dista[it.first][0])
                {
                    int v1, v2;
                    v1 = dista[it.first][0];
                    dista[it.first][0] = val1;
                    dista[it.first][1] = v1;
                    sort(dista[it.first].begin(), dista[it.first].end());
                    q.push({val1, it.first});
                }
                else if (val1 <= dista[it.first][1])
                {
                    dista[it.first][1] = val1;
                    sort(dista[it.first].begin(), dista[it.first].end());
                    q.push({val1, it.first});
                }
            }
        }
    }
}
void solve()
{
    int k;
    cin >> n >> m >> k;
    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;
        have.push_back(a);
    }
    dij();
    cout << dista[0][1] << endl;
}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    long long int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Compilation message

crocodile.cpp: In function 'void dij()':
crocodile.cpp:50:29: warning: unused variable 'v2' [-Wunused-variable]
   50 |                     int v1, v2;
      |                             ^~
crocodile.cpp:22:9: warning: unused variable 'val' [-Wunused-variable]
   22 |     int val = 5;
      |         ^~~
/tmp/ccPWYBWs.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc0awhY0.o:crocodile.cpp:(.text.startup+0x0): first defined here
/tmp/ccPWYBWs.o: In function `main':
grader.cpp:(.text.startup+0x2d): undefined reference to `travel_plan(int, int, int (*) [2], int*, int, int*)'
collect2: error: ld returned 1 exit status