Submission #714717

#TimeUsernameProblemLanguageResultExecution timeMemory
714717IliyaToll (BOI17_toll)C++17
18 / 100
3083 ms6040 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5e4 + 10; const int Inf = 0x3f3f3f3f; vector<pair<int, int>> Adj[N], Order[N]; int n, m, k, o, D[N], mark[N], ans[N]; void Dijkstra(int v) { memset(D, 63, sizeof D); memset(mark, 0, sizeof mark); D[v] = 0; priority_queue<pair<int, int>> PQ; PQ.emplace(0, v); while (!PQ.empty()) { int v = PQ.top().second; PQ.pop(); if (mark[v]) continue; mark[v] = true; for (auto [u, w] : Adj[v]) if (D[u] > D[v] + w) D[u] = D[v] + w, PQ.emplace(-D[u], u); } } signed main() { scanf("%d%d%d%d", &k, &n, &m, &o); for (int i = 0; i < m; i++) { int a, b, t; scanf("%d%d%d", &a, &b, &t); Adj[a].emplace_back(b, t); } vector<int> V; for (int i = 0; i < o; i++) { int a, b; scanf("%d%d", &a, &b); Order[a].emplace_back(b, i); V.push_back(a); } sort(V.begin(), V.end()); V.resize(unique(V.begin(), V.end()) - V.begin()); for (int x : V) { Dijkstra(x); for (auto [u, i] : Order[x]) ans[i] = D[u]; } for (int i = 0; i < o; i++) printf("%d\n", (ans[i] == Inf ? -1 : ans[i])); return 0; }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |  scanf("%d%d%d%d", &k, &n, &m, &o);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%d%d%d", &a, &b, &t);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d%d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...