QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#113166 | #4437. Link with Running | Tobo# | WA | 855ms | 52752kb | C++20 | 2.3kb | 2023-06-16 16:18:49 | 2023-06-16 16:18:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define N 100005
using i64 = long long;
int n, m, vis[N];
i64 dis1[N], dis2[N];
vector<array<int, 3>> G[N], H[N];
vector<pair<int, int>> adj[N];
void solve()
{
cin >> n >> m;
for (int i = 1, u, v, x, y; i <= m; i++)
{
cin >> u >> v >> x >> y;
G[u].push_back({v, x, y});
H[v].push_back({u, x, y});
}
for (int i = 1; i <= n; i++)
vis[i] = 0, dis1[i] = 1e18;
priority_queue<pair<i64, int>> que;
que.push({0, 1});
dis1[1] = 0;
while (!que.empty())
{
int cur = que.top().second;
que.pop();
if (vis[cur])
continue;
vis[cur] = 1;
for (auto [i, val, _] : G[cur])
{
if (dis1[i] > dis1[cur] + val)
{
dis1[i] = dis1[cur] + val;
que.push({-dis1[i], i});
}
}
}
for (int i = 1; i <= n; i++)
vis[i] = 0, dis2[i] = 1e18;
que.push({0, n});
dis2[n] = 0;
while (!que.empty())
{
int cur = que.top().second;
que.pop();
if (vis[cur])
continue;
vis[cur] = 1;
for (auto [i, val, _] : H[cur])
{
if (dis2[i] > dis2[cur] + val)
{
dis2[i] = dis2[cur] + val;
que.push({-dis2[i], i});
}
}
}
i64 mindis = dis1[n];
cout << dis1[n] << ' ';
vector<i64> ans(n + 1);
vector<int> degree(n + 1);
for (int i = 1; i <= n; i++)
for (auto &[j, val, h] : G[i])
if (dis1[i] + val + dis2[j] == mindis)
adj[i].push_back({j, h}), degree[j]++;
queue<int> tque;
tque.push(1);
while (!tque.empty())
{
int cur = tque.front();
tque.pop();
for (auto [i, val] : adj[cur])
{
ans[i] = max(ans[i], ans[cur] + val);
if (!--degree[i])
tque.push(i);
}
}
cout << ans[n] << '\n';
for (int i = 1; i <= n; i++)
G[i].clear(), H[i].clear(), adj[i].clear();
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 855ms
memory: 52752kb
input:
12 100000 200000 1 2 838279516 902819511 1 3 293478832 513256010 2 4 682688353 204481674 2 5 360092507 651108247 5 6 519851939 323803002 6 7 675439277 205804465 7 8 419167205 386168059 6 9 140767493 382483305 9 10 558115401 613738466 9 11 902235661 744659643 9 12 851394758 1720015 12 13 635355827 46...
output:
5927443549 11285847934 2529348 325344428756 2522027 438209666288 250100947 25049026205784 249512452 24966236662852 0 0 0 0 0 1000000000 0 1 0 0 0 1 0 1
result:
wrong answer 6th lines differ - expected: '0 9535132634', found: '0 0'