Submission #758945

# Submission time Handle Problem Language Result Execution time Memory
758945 2023-06-15T15:01:15 Z Dexva Voting Cities (NOI22_votingcity) C++14
0 / 100
5 ms 1236 KB
#include <bits/stdc++.h>
using namespace std;

#define lln long long
const long long INF = numeric_limits<long long>::max();
using pll = pair<long,long>;

void solve() {
    lln N, E, K; cin >> N >> E >> K;
    vector<lln> cities(N+1), vcities(K); //cities are 0-indexed,, 1 city will be the mega target (coalsced voting cities)
    vector<pll> roads(E);
    map<lln, vector<pll> > adj;
    
    for (lln i=0;i<K;i++) cin >> vcities[i]; //list of voting cities
    for (lln i=0;i<E;i++) {
        lln u, v, c; cin >> u >> v >> c; //we reverse the graph so instead of u->v, v-> u (see notes for subtask 2)
        adj[v].push_back({u,c});
    }

    //connecting mega target (which is city `N`)
    for (auto& vc : vcities) adj[N].push_back({vc,0});

    //dijkstra proper
    vector<lln> d(N+1,INF);
    vector<bool> done(N+1,false);
    lln source = N;
    priority_queue<pll, vector<pll>, greater<pll> > pq;

    pq.push({0, source});  // first parameter of pll is the distance/total weight, second parameter is index
    d[source] = 0;

    while(!pq.empty()) {
        auto& [sofar, city] = pq.top(); pq.pop();
        if (!done[city]) {
            for(auto& [to, cost] : adj[city]) {
                if (d[to]>sofar+cost) {
                    d[to] = sofar + cost;
                    pq.push({d[to], to});
                }
            }
        }
    }

    //Queries stuff
    lln Q; cin >> Q;
    for (lln q=0;q<Q;q++) {
        lln asked; cin >> asked;
        vector<lln> tickets(5);
        for (lln i=0;i<5;i++) cin >> tickets[i];
        if (d[asked]==INF) cout << -1 << '\n';
        else cout << d[asked] << '\n';
    }

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lln t = 1;
    while (t--) solve();
    return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:33:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |         auto& [sofar, city] = pq.top(); pq.pop();
      |               ^
Main.cpp:35:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   35 |             for(auto& [to, cost] : adj[city]) {
      |                       ^
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -