# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1084157 |
2024-09-05T12:37:20 Z |
I_FloPPed21 |
Robot (JOI21_ho_t4) |
C++14 |
|
787 ms |
89020 KB |
#include <bits/stdc++.h>
using namespace std;
int n,m;
struct muchie
{
int to,p;
long long c;
};
map<int,vector<muchie>>adj[200005];
long long dp[200005];
map<int,long long>dp2[100005],sum[100005];
int main()
{
cin>>n>>m;
for(int i=1; i<=n; i++)
dp[i]=1e18;
dp[1]=0;
for(int i=1; i<=m; i++)
{
int a,b,p;
long long c;
cin>>a>>b>>p>>c;
adj[a][p].push_back({b,p,c});
adj[b][p].push_back({a,p,c});
sum[a][p]+=c;
sum[b][p]+=c;
}
priority_queue<pair<long long,pair<int,int>>>pq;
pq.push({0,{1,0}});
while(!pq.empty())
{
int nod,p;
long long c;
nod=pq.top().second.first,c=pq.top().first,p=pq.top().second.second;
pq.pop();
if(p!=0)
{
if(-c!=dp2[nod][p])
continue;
for(muchie u:adj[nod][p])
{
long long cost=sum[nod][p]-u.c-c;
if(cost<dp[u.to])
{
dp[u.to]=cost;
pq.push({-dp[u.to],{u.to,0}});
}
}
}
else
{
if(-c!=dp[nod])
continue;
for(auto &u :adj[nod])
{
for(auto k :u.second)
{
int p=k.p;
long long caz1=sum[nod][p]-k.c;
if(caz1-c<dp[k.to])
{
dp[k.to]=caz1-c;
pq.push({-dp[k.to],{k.to,0}});
}
long long caz2=k.c-c;
if(caz2<dp[k.to])
{
dp[k.to]=caz2;
pq.push({-dp[k.to],{k.to,0}});
}
long long caz3=-c;
if(!dp2[k.to].count(p) || caz3<dp2[k.to][p])
{
dp2[k.to][p]=caz3;
pq.push({-dp2[k.to][p],{k.to,p}});
}
}
}
}
}
if(dp[n]==1e18)
cout<<-1<<'\n';
else
cout<<dp[n]<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19036 KB |
Output is correct |
2 |
Correct |
9 ms |
19036 KB |
Output is correct |
3 |
Correct |
8 ms |
19036 KB |
Output is correct |
4 |
Correct |
8 ms |
19064 KB |
Output is correct |
5 |
Correct |
8 ms |
19032 KB |
Output is correct |
6 |
Correct |
9 ms |
19160 KB |
Output is correct |
7 |
Correct |
9 ms |
19292 KB |
Output is correct |
8 |
Correct |
9 ms |
19292 KB |
Output is correct |
9 |
Correct |
13 ms |
19804 KB |
Output is correct |
10 |
Correct |
11 ms |
19588 KB |
Output is correct |
11 |
Correct |
10 ms |
19548 KB |
Output is correct |
12 |
Correct |
12 ms |
19548 KB |
Output is correct |
13 |
Correct |
11 ms |
19548 KB |
Output is correct |
14 |
Correct |
12 ms |
19548 KB |
Output is correct |
15 |
Correct |
10 ms |
19292 KB |
Output is correct |
16 |
Correct |
11 ms |
19548 KB |
Output is correct |
17 |
Correct |
11 ms |
19548 KB |
Output is correct |
18 |
Correct |
9 ms |
19292 KB |
Output is correct |
19 |
Correct |
11 ms |
19288 KB |
Output is correct |
20 |
Correct |
10 ms |
19484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
168 ms |
39300 KB |
Output is correct |
2 |
Correct |
58 ms |
29260 KB |
Output is correct |
3 |
Correct |
146 ms |
36172 KB |
Output is correct |
4 |
Correct |
86 ms |
32460 KB |
Output is correct |
5 |
Correct |
749 ms |
87400 KB |
Output is correct |
6 |
Correct |
583 ms |
76596 KB |
Output is correct |
7 |
Correct |
315 ms |
60960 KB |
Output is correct |
8 |
Correct |
337 ms |
55892 KB |
Output is correct |
9 |
Correct |
345 ms |
55580 KB |
Output is correct |
10 |
Correct |
228 ms |
52432 KB |
Output is correct |
11 |
Correct |
107 ms |
37456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19036 KB |
Output is correct |
2 |
Correct |
9 ms |
19036 KB |
Output is correct |
3 |
Correct |
8 ms |
19036 KB |
Output is correct |
4 |
Correct |
8 ms |
19064 KB |
Output is correct |
5 |
Correct |
8 ms |
19032 KB |
Output is correct |
6 |
Correct |
9 ms |
19160 KB |
Output is correct |
7 |
Correct |
9 ms |
19292 KB |
Output is correct |
8 |
Correct |
9 ms |
19292 KB |
Output is correct |
9 |
Correct |
13 ms |
19804 KB |
Output is correct |
10 |
Correct |
11 ms |
19588 KB |
Output is correct |
11 |
Correct |
10 ms |
19548 KB |
Output is correct |
12 |
Correct |
12 ms |
19548 KB |
Output is correct |
13 |
Correct |
11 ms |
19548 KB |
Output is correct |
14 |
Correct |
12 ms |
19548 KB |
Output is correct |
15 |
Correct |
10 ms |
19292 KB |
Output is correct |
16 |
Correct |
11 ms |
19548 KB |
Output is correct |
17 |
Correct |
11 ms |
19548 KB |
Output is correct |
18 |
Correct |
9 ms |
19292 KB |
Output is correct |
19 |
Correct |
11 ms |
19288 KB |
Output is correct |
20 |
Correct |
10 ms |
19484 KB |
Output is correct |
21 |
Correct |
168 ms |
39300 KB |
Output is correct |
22 |
Correct |
58 ms |
29260 KB |
Output is correct |
23 |
Correct |
146 ms |
36172 KB |
Output is correct |
24 |
Correct |
86 ms |
32460 KB |
Output is correct |
25 |
Correct |
749 ms |
87400 KB |
Output is correct |
26 |
Correct |
583 ms |
76596 KB |
Output is correct |
27 |
Correct |
315 ms |
60960 KB |
Output is correct |
28 |
Correct |
337 ms |
55892 KB |
Output is correct |
29 |
Correct |
345 ms |
55580 KB |
Output is correct |
30 |
Correct |
228 ms |
52432 KB |
Output is correct |
31 |
Correct |
107 ms |
37456 KB |
Output is correct |
32 |
Correct |
148 ms |
32976 KB |
Output is correct |
33 |
Correct |
140 ms |
33996 KB |
Output is correct |
34 |
Correct |
321 ms |
54972 KB |
Output is correct |
35 |
Correct |
208 ms |
46016 KB |
Output is correct |
36 |
Correct |
255 ms |
51692 KB |
Output is correct |
37 |
Correct |
293 ms |
54028 KB |
Output is correct |
38 |
Correct |
297 ms |
60444 KB |
Output is correct |
39 |
Correct |
167 ms |
36552 KB |
Output is correct |
40 |
Correct |
342 ms |
56916 KB |
Output is correct |
41 |
Correct |
366 ms |
57172 KB |
Output is correct |
42 |
Correct |
399 ms |
65464 KB |
Output is correct |
43 |
Correct |
150 ms |
41672 KB |
Output is correct |
44 |
Correct |
291 ms |
47304 KB |
Output is correct |
45 |
Correct |
276 ms |
52248 KB |
Output is correct |
46 |
Correct |
233 ms |
52560 KB |
Output is correct |
47 |
Correct |
288 ms |
53800 KB |
Output is correct |
48 |
Correct |
787 ms |
89020 KB |
Output is correct |