Submission #425814

# Submission time Handle Problem Language Result Execution time Memory
425814 2021-06-13T11:40:22 Z dxz05 Crocodile's Underground City (IOI11_crocodile) C++14
0 / 100
6 ms 7372 KB
#include "crocodile.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MP make_pair

const ll INF = 1e18 + 1e8;
const int N = 3e5 + 3e2;

vector<pair<int, int>> g[N];

ll dp[N];
bool processed[N];
int cnt[N];

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
    for (int i = 0; i < M; i++){
        g[R[i][0]].emplace_back(R[i][1], L[i]);
        g[R[i][1]].emplace_back(R[i][0], L[i]);
    }

    fill(dp, dp + N, INF);

    for (int i = 0; i < K; i++){
        dp[P[i]] = 0;
    }

    set<pair<int, int>> s;

    for (int i = 0; i < N; i++){
        if (dp[i] == 0) continue;
        for (auto edge : g[i]){
            int j = edge.first, w = edge.second;
            if (dp[j] != INF) cnt[i]++;
        }
        s.insert(MP(cnt[i], i));
    }

    while (!s.empty()){
        int x = s.rbegin()->second;
        //assert(s.begin()->first >= 2);
        s.erase(MP(cnt[x], x));

        vector<ll> vec;

        for (auto edge : g[x]){
            int y = edge.first, w = edge.second;
            vec.push_back(dp[y] + w);
        }

        sort(vec.begin(), vec.end());

        //for (ll val : vec) cout << val << ' '; cout << endl;

        dp[x] = vec[1];
        //cout << x << ' ' << dp[x] << endl;

        for (auto edge : g[x]){
            int y = edge.second, w = edge.second;
            if (s.find(MP(cnt[y], y)) != s.end()){
                s.erase(MP(cnt[y], y));
                cnt[y]++;
                s.insert(MP(cnt[y], y));
            }
        }
    }

    //for (int i = 0; i < N; i++) cout << dp[i] << ' ';

    return dp[0];
}


Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:36:33: warning: unused variable 'w' [-Wunused-variable]
   36 |             int j = edge.first, w = edge.second;
      |                                 ^
crocodile.cpp:62:34: warning: unused variable 'w' [-Wunused-variable]
   62 |             int y = edge.second, w = edge.second;
      |                                  ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Incorrect 6 ms 7372 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Incorrect 6 ms 7372 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Incorrect 6 ms 7372 KB Output isn't correct
5 Halted 0 ms 0 KB -