QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#60406 | #4437. Link with Running | qinjianbin# | WA | 1003ms | 36820kb | C++17 | 1.4kb | 2022-11-04 15:05:41 | 2022-11-04 15:05:43 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
struct Edge
{
int v; ll w, p;
bool operator < (const Edge& rhs) const
{
return w > rhs.w;
}
};
vector<Edge> g[N];
int deg[N], n, m;
ll d[N], dp[N];
void solve()
{
_for(i, 1, n) d[i] = 1e18;
d[1] = 0;
priority_queue<Edge> q;
q.push({1, d[1], 0});
while(!q.empty())
{
Edge x = q.top(); q.pop();
int u = x.v;
if(d[u] != x.w) continue;
for(auto [v, w, p]: g[u])
if(d[v] > d[u] + w)
{
d[v] = d[u] + w;
q.push({v, d[v], 0});
}
}
}
int main()
{
int T; scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
_for(i, 1, n) g[i].clear();
while(m--)
{
int u, v, w, p;
scanf("%d%d%d%d", &u, &v, &w, &p);
g[u].push_back({v, w, p});
}
solve();
printf("%lld ", d[n]);
_for(i, 1, n) dp[i] = deg[i] = 0;
_for(u, 1, n)
for(auto [v, w, p]: g[u])
if(d[v] == d[u] + w)
deg[v]++;
queue<int> q;
_for(i, 1, n)
if(!deg[i])
q.push(i);
while(!q.empty())
{
int u = q.front(); q.pop();
for(auto [v, w, p]: g[u])
if(d[v] == d[u] + w)
{
dp[v] = max(dp[v], dp[u] + p);
if(--deg[v]== 0) q.push(v);
}
}
printf("%lld\n", dp[n]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1003ms
memory: 36820kb
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 0
result:
wrong answer 6th lines differ - expected: '0 9535132634', found: '0 0'