# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
714728 | Iliya | Toll (BOI17_toll) | C++17 | 3067 ms | 6144 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], Order;
int n, m, k, o, C[N], D[N], mark[N];
void DFS(int v, int comp)
{
mark[v] = true;
C[v] = comp;
for (auto [u, w] : Adj[v])
D[u] = D[v] + w, DFS(u, comp);
}
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);
}
for (int i = 0; i < o; i++)
{
int a, b;
scanf("%d%d", &a, &b);
Order.emplace_back(a, b);
}
for (int i = 0; i < n; i++)
if (!mark[i]) DFS(i, i);
for (auto [u, v] : Order)
{
if (u < v) swap(u, v);
if (C[u] == C[v])
printf("%d\n", D[u] - D[v]);
else
printf("%d\n", -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... |