# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
476797 |
2021-09-28T14:09:35 Z |
Rainbowbunny |
Robot (JOI21_ho_t4) |
C++17 |
|
1450 ms |
118220 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long INF = 1e18;
struct ToEdge
{
int v, c;
long long p;
ToEdge(int v = 0, int c = 0, long long p = 0) : v(v), c(c), p(p) {}
};
priority_queue <tuple <long long, int, int>, vector <tuple <long long, int, int> >, greater <tuple <long long, int, int> > > pq;
int n, m;
long long p[MAXN];
vector <ToEdge> E[MAXN];
map <int, long long> Sum[MAXN];
map <int, vector <ToEdge> > Adj[MAXN];
map <int, long long> Dist[MAXN];
void Add(long long dist, int node, int color)
{
if(Dist[node][color] > dist)
{
Dist[node][color] = dist;
pq.push(make_tuple(dist, node, color));
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
int u, v, c;
long long p;
cin >> u >> v >> c >> p;
E[u].emplace_back(v, c, p);
E[v].emplace_back(u, c, p);
Adj[u][c].emplace_back(v, c, p);
Adj[v][c].emplace_back(u, c, p);
Dist[u][c] = INF;
Dist[v][c] = INF;
Sum[u][c] += p;
Sum[v][c] += p;
}
for(int i = 1; i <= n; i++)
{
Dist[i][0] = INF;
}
Add(0, 1, 0);
while(pq.empty() == false)
{
int node, color;
long long dist;
tie(dist, node, color) = pq.top();
pq.pop();
if(dist == Dist[node][color])
{
if(color == 0)
{
for(auto x : E[node])
{
Add(dist, x.v, x.c);
Add(dist + min(Sum[node][x.c] - x.p, x.p), x.v, 0);
assert(Sum[node][x.c] - x.p >= 0);
}
}
else
{
for(auto x : Adj[node][color])
{
Add(dist + Sum[node][color] - x.p, x.v, 0);
assert(Sum[node][color] - x.p >= 0);
}
}
}
}
if(Dist[n][0] == INF)
{
Dist[n][0] = -1;
}
cout << Dist[n][0] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
33144 KB |
Output is correct |
2 |
Correct |
18 ms |
33148 KB |
Output is correct |
3 |
Correct |
18 ms |
33176 KB |
Output is correct |
4 |
Correct |
19 ms |
33132 KB |
Output is correct |
5 |
Correct |
16 ms |
33160 KB |
Output is correct |
6 |
Correct |
18 ms |
33140 KB |
Output is correct |
7 |
Correct |
18 ms |
33328 KB |
Output is correct |
8 |
Correct |
18 ms |
33228 KB |
Output is correct |
9 |
Correct |
23 ms |
33976 KB |
Output is correct |
10 |
Correct |
21 ms |
33864 KB |
Output is correct |
11 |
Correct |
19 ms |
33652 KB |
Output is correct |
12 |
Correct |
19 ms |
33700 KB |
Output is correct |
13 |
Correct |
20 ms |
33740 KB |
Output is correct |
14 |
Correct |
20 ms |
33712 KB |
Output is correct |
15 |
Correct |
18 ms |
33532 KB |
Output is correct |
16 |
Correct |
21 ms |
33688 KB |
Output is correct |
17 |
Correct |
21 ms |
33744 KB |
Output is correct |
18 |
Correct |
18 ms |
33416 KB |
Output is correct |
19 |
Correct |
21 ms |
33500 KB |
Output is correct |
20 |
Correct |
20 ms |
33696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
334 ms |
57444 KB |
Output is correct |
2 |
Correct |
135 ms |
45340 KB |
Output is correct |
3 |
Correct |
408 ms |
55660 KB |
Output is correct |
4 |
Correct |
206 ms |
49728 KB |
Output is correct |
5 |
Correct |
1411 ms |
114072 KB |
Output is correct |
6 |
Correct |
1195 ms |
103056 KB |
Output is correct |
7 |
Correct |
507 ms |
82828 KB |
Output is correct |
8 |
Correct |
660 ms |
81096 KB |
Output is correct |
9 |
Correct |
701 ms |
81220 KB |
Output is correct |
10 |
Correct |
520 ms |
75164 KB |
Output is correct |
11 |
Correct |
340 ms |
63816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
33144 KB |
Output is correct |
2 |
Correct |
18 ms |
33148 KB |
Output is correct |
3 |
Correct |
18 ms |
33176 KB |
Output is correct |
4 |
Correct |
19 ms |
33132 KB |
Output is correct |
5 |
Correct |
16 ms |
33160 KB |
Output is correct |
6 |
Correct |
18 ms |
33140 KB |
Output is correct |
7 |
Correct |
18 ms |
33328 KB |
Output is correct |
8 |
Correct |
18 ms |
33228 KB |
Output is correct |
9 |
Correct |
23 ms |
33976 KB |
Output is correct |
10 |
Correct |
21 ms |
33864 KB |
Output is correct |
11 |
Correct |
19 ms |
33652 KB |
Output is correct |
12 |
Correct |
19 ms |
33700 KB |
Output is correct |
13 |
Correct |
20 ms |
33740 KB |
Output is correct |
14 |
Correct |
20 ms |
33712 KB |
Output is correct |
15 |
Correct |
18 ms |
33532 KB |
Output is correct |
16 |
Correct |
21 ms |
33688 KB |
Output is correct |
17 |
Correct |
21 ms |
33744 KB |
Output is correct |
18 |
Correct |
18 ms |
33416 KB |
Output is correct |
19 |
Correct |
21 ms |
33500 KB |
Output is correct |
20 |
Correct |
20 ms |
33696 KB |
Output is correct |
21 |
Correct |
334 ms |
57444 KB |
Output is correct |
22 |
Correct |
135 ms |
45340 KB |
Output is correct |
23 |
Correct |
408 ms |
55660 KB |
Output is correct |
24 |
Correct |
206 ms |
49728 KB |
Output is correct |
25 |
Correct |
1411 ms |
114072 KB |
Output is correct |
26 |
Correct |
1195 ms |
103056 KB |
Output is correct |
27 |
Correct |
507 ms |
82828 KB |
Output is correct |
28 |
Correct |
660 ms |
81096 KB |
Output is correct |
29 |
Correct |
701 ms |
81220 KB |
Output is correct |
30 |
Correct |
520 ms |
75164 KB |
Output is correct |
31 |
Correct |
340 ms |
63816 KB |
Output is correct |
32 |
Correct |
199 ms |
54628 KB |
Output is correct |
33 |
Correct |
267 ms |
54972 KB |
Output is correct |
34 |
Correct |
623 ms |
78520 KB |
Output is correct |
35 |
Correct |
479 ms |
69040 KB |
Output is correct |
36 |
Correct |
474 ms |
77096 KB |
Output is correct |
37 |
Correct |
600 ms |
82980 KB |
Output is correct |
38 |
Correct |
526 ms |
90528 KB |
Output is correct |
39 |
Correct |
232 ms |
59960 KB |
Output is correct |
40 |
Correct |
700 ms |
85560 KB |
Output is correct |
41 |
Correct |
721 ms |
85680 KB |
Output is correct |
42 |
Correct |
742 ms |
95984 KB |
Output is correct |
43 |
Correct |
330 ms |
63440 KB |
Output is correct |
44 |
Correct |
649 ms |
72496 KB |
Output is correct |
45 |
Correct |
597 ms |
79556 KB |
Output is correct |
46 |
Correct |
446 ms |
79616 KB |
Output is correct |
47 |
Correct |
485 ms |
80468 KB |
Output is correct |
48 |
Correct |
1450 ms |
118220 KB |
Output is correct |