# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
789797 |
2023-07-22T04:35:33 Z |
Hanksburger |
Robot (JOI21_ho_t4) |
C++17 |
|
332 ms |
64716 KB |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, pair<long long, long long> > > adj[100005];
vector<pair<long long, long long> > vec[300005];
priority_queue<pair<long long, long long> > pq;
long long dist[300005], final[300005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, sz;
cin >> n >> m;
for (long long i=1; i<=m; i++)
{
long long u, v, c, p;
cin >> u >> v >> c >> p;
adj[u].push_back({c, {v, p}});
adj[v].push_back({c, {u, p}});
vec[u].push_back({v, p});
vec[v].push_back({u, p});
}
sz=n;
for (long long i=1; i<=n; i++)
{
sort(adj[i].begin(), adj[i].end());
long long ind=0;
for (long long j=1; j<adj[i].size(); j++)
{
if (adj[i][ind].first!=adj[i][j].first)
{
if (j-ind==1)
vec[i].push_back({adj[i][ind].second.first, 0});
else
{
long long sum=0;
for (long long k=ind; k<j; k++)
sum+=adj[i][k].second.second;
sz++;
vec[i].push_back({sz, 0});
for (long long k=ind; k<j; k++)
{
vec[adj[i][k].second.first].push_back({sz, 0});
vec[sz].push_back({adj[i][k].second.first, sum-adj[i][k].second.second});
}
}
ind=j;
}
}
long long j=adj[i].size();
if (j-ind==1)
vec[i].push_back({adj[i][ind].second.first, 0});
else
{
long long sum=0;
for (long long k=ind; k<j; k++)
sum+=adj[i][k].second.second;
sz++;
vec[i].push_back({sz, 0});
for (long long k=ind; k<j; k++)
{
vec[adj[i][k].second.first].push_back({sz, 0});
vec[sz].push_back({adj[i][k].second.first, sum-adj[i][k].second.second});
}
}
}
for (long long i=1; i<=sz; i++)
dist[i]=1e18;
dist[1]=0;
pq.push({0, 1});
while (!pq.empty())
{
long long u=pq.top().second;
pq.pop();
if (final[u])
continue;
final[u]=1;
for (long long i=0; i<vec[u].size(); i++)
{
long long v=vec[u][i].first, w=vec[u][i].second;
if (dist[u]+w<dist[v])
{
dist[v]=dist[u]+w;
if (!final[v])
pq.push({-dist[v], v});
}
}
}
if (dist[n]<5e17)
cout << dist[n];
else
cout << -1;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:28:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (long long j=1; j<adj[i].size(); j++)
| ~^~~~~~~~~~~~~~
Main.cpp:78:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (long long i=0; i<vec[u].size(); i++)
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
4 ms |
9684 KB |
Output is correct |
5 |
Correct |
4 ms |
9684 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9812 KB |
Output is correct |
8 |
Correct |
4 ms |
9812 KB |
Output is correct |
9 |
Correct |
6 ms |
10196 KB |
Output is correct |
10 |
Correct |
6 ms |
10196 KB |
Output is correct |
11 |
Correct |
6 ms |
10196 KB |
Output is correct |
12 |
Correct |
6 ms |
10196 KB |
Output is correct |
13 |
Correct |
6 ms |
10196 KB |
Output is correct |
14 |
Correct |
6 ms |
10196 KB |
Output is correct |
15 |
Correct |
5 ms |
10068 KB |
Output is correct |
16 |
Correct |
6 ms |
10260 KB |
Output is correct |
17 |
Correct |
6 ms |
10068 KB |
Output is correct |
18 |
Correct |
5 ms |
9812 KB |
Output is correct |
19 |
Correct |
5 ms |
10204 KB |
Output is correct |
20 |
Correct |
6 ms |
10144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
29196 KB |
Output is correct |
2 |
Correct |
36 ms |
18020 KB |
Output is correct |
3 |
Correct |
128 ms |
40996 KB |
Output is correct |
4 |
Correct |
59 ms |
22460 KB |
Output is correct |
5 |
Correct |
224 ms |
52536 KB |
Output is correct |
6 |
Correct |
235 ms |
57324 KB |
Output is correct |
7 |
Correct |
225 ms |
61004 KB |
Output is correct |
8 |
Correct |
318 ms |
63268 KB |
Output is correct |
9 |
Correct |
323 ms |
63204 KB |
Output is correct |
10 |
Correct |
147 ms |
40512 KB |
Output is correct |
11 |
Correct |
100 ms |
35804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
4 ms |
9684 KB |
Output is correct |
5 |
Correct |
4 ms |
9684 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9812 KB |
Output is correct |
8 |
Correct |
4 ms |
9812 KB |
Output is correct |
9 |
Correct |
6 ms |
10196 KB |
Output is correct |
10 |
Correct |
6 ms |
10196 KB |
Output is correct |
11 |
Correct |
6 ms |
10196 KB |
Output is correct |
12 |
Correct |
6 ms |
10196 KB |
Output is correct |
13 |
Correct |
6 ms |
10196 KB |
Output is correct |
14 |
Correct |
6 ms |
10196 KB |
Output is correct |
15 |
Correct |
5 ms |
10068 KB |
Output is correct |
16 |
Correct |
6 ms |
10260 KB |
Output is correct |
17 |
Correct |
6 ms |
10068 KB |
Output is correct |
18 |
Correct |
5 ms |
9812 KB |
Output is correct |
19 |
Correct |
5 ms |
10204 KB |
Output is correct |
20 |
Correct |
6 ms |
10144 KB |
Output is correct |
21 |
Correct |
86 ms |
29196 KB |
Output is correct |
22 |
Correct |
36 ms |
18020 KB |
Output is correct |
23 |
Correct |
128 ms |
40996 KB |
Output is correct |
24 |
Correct |
59 ms |
22460 KB |
Output is correct |
25 |
Correct |
224 ms |
52536 KB |
Output is correct |
26 |
Correct |
235 ms |
57324 KB |
Output is correct |
27 |
Correct |
225 ms |
61004 KB |
Output is correct |
28 |
Correct |
318 ms |
63268 KB |
Output is correct |
29 |
Correct |
323 ms |
63204 KB |
Output is correct |
30 |
Correct |
147 ms |
40512 KB |
Output is correct |
31 |
Correct |
100 ms |
35804 KB |
Output is correct |
32 |
Correct |
96 ms |
43352 KB |
Output is correct |
33 |
Correct |
115 ms |
39908 KB |
Output is correct |
34 |
Correct |
182 ms |
47764 KB |
Output is correct |
35 |
Correct |
147 ms |
41340 KB |
Output is correct |
36 |
Correct |
203 ms |
47208 KB |
Output is correct |
37 |
Correct |
251 ms |
56168 KB |
Output is correct |
38 |
Correct |
219 ms |
63936 KB |
Output is correct |
39 |
Correct |
124 ms |
56244 KB |
Output is correct |
40 |
Correct |
332 ms |
64708 KB |
Output is correct |
41 |
Correct |
323 ms |
64716 KB |
Output is correct |
42 |
Correct |
286 ms |
57884 KB |
Output is correct |
43 |
Correct |
93 ms |
35056 KB |
Output is correct |
44 |
Correct |
162 ms |
60964 KB |
Output is correct |
45 |
Correct |
244 ms |
50856 KB |
Output is correct |
46 |
Correct |
204 ms |
48460 KB |
Output is correct |
47 |
Correct |
234 ms |
51936 KB |
Output is correct |
48 |
Correct |
245 ms |
61632 KB |
Output is correct |