# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
714683 | Iliya | Toll (BOI17_toll) | C++17 | 37 ms | 3620 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |