Submission #714683

#TimeUsernameProblemLanguageResultExecution timeMemory
714683IliyaToll (BOI17_toll)C++17
0 / 100
37 ms3620 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]; vector<pair<int, int>> Order; int k, n, m, o; void Subtask1() { vector<int> dp(n); for (int i = 0; i < n; i++) for (auto [u, w] : Adj[i]) dp[u] = dp[i] + w; for (auto [l, r] : Order) printf("%d\n", dp[r] - dp[l]); } void Subtask2() { vector<int> dp(n, Inf); dp[0] = 0; for (int i = 0; i < n; i++) { if (dp[i] == Inf) continue; for (auto [u, w] : Adj[i]) dp[u] = min(dp[u], dp[i] + w); } for (auto [l, r] : Order) printf("%d\n", (dp[r] == Inf ? -1 : dp[r])); } 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); } int cnt = 0; for (int i = 0; i < o; i++) { int a, b; scanf("%d%d", &a, &b); Order.emplace_back(a, b); if (a == 0) cnt++; } if (k == 1) {Subtask1(); return 0;} if (cnt == o) {Subtask2(); return 0;} printf("-1"); return 0; }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  scanf("%d%d%d%d", &k, &n, &m, &o);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d%d%d", &a, &b, &t);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   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...