#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const ll MAX_EDGES = 2505;
const ll INF = 1LL << 60;
vector<ll> to, pred, head, cost;
vector<vector<ll>> rev_adj;
ll dist[MAX_EDGES][MAX_EDGES];
vector<pair<ll, ll>> best_edges[MAX_EDGES][MAX_EDGES / 2];
#define VEVE(i, a, b) for (ll i = a, __##i = b; i < __##i; ++i)
#define RARA(i, a, b) for (ll i = a, __##i = b; i > __##i; --i)
#define VERA(x, seq) for (auto &x : seq)
#define SIZE(x) ((ll)(x.size()))
#define ALL(x) x.begin(), x.end()
void Min(ll& a, ll b) { a = min(a, b); }
void ComputeDist(ll n, ll m) {
priority_queue<pair<ll, ll>> pq;
vector<ll> inc_count(n);
auto calc = [&](ll src_edge) {
fill(ALL(inc_count), 0);
dist[src_edge][src_edge] = 0;
pq.emplace(0, src_edge);
while (not pq.empty()) {
const auto cur_dist = -pq.top().first;
const auto edge = pq.top().second;
pq.pop();
if (cur_dist > dist[src_edge][edge])
continue;
if (++inc_count[to[edge]] > 2)
continue;
best_edges[src_edge][to[edge]].emplace_back(edge, cur_dist);
for (ll nx_edge = head[to[edge]]; ~nx_edge; nx_edge = pred[nx_edge]) {
if ((edge ^ nx_edge) == 1)
continue;
if (cur_dist + cost[nx_edge] < dist[src_edge][nx_edge]) {
dist[src_edge][nx_edge] = cur_dist + cost[nx_edge];
pq.emplace(-dist[src_edge][nx_edge], nx_edge);
}
}
}
};
memset(dist, 0x3F, sizeof(dist));
VEVE(e, 0, m) {
calc(e);
}
}
void Solve(ll) {
ll n, m, t, l;
scanf("%lld %lld %lld %lld", &n, &m, &t, &l);
assert(t == 1);
head.resize(n, -1);
VEVE(e, 0, m) {
ll a, b, c;
scanf("%lld %lld %lld", &a, &b, &c);
--a, --b;
to.push_back(b);
cost.push_back(c);
pred.push_back(head[a]);
head[a] = SIZE(pred) - 1;
// rev_adj[b].push_back(head[a]);
to.push_back(a);
cost.push_back(c);
pred.push_back(head[b]);
head[b] = SIZE(pred) - 1;
// rev_adj[a].push_back(head[b]);
}
m *= 2;
ComputeDist(n, m);
vector<ll> supply(l);
VERA(s, supply) {
scanf("%d", &s);
--s;
}
vector<ll> dp_cur(m), dp_pred(m);
VEVE(_, 0, t) {
ll p, q;
scanf("%lld %lld", &p, &q);
--p, --q;
supply[p] = q;
fill(ALL(dp_pred), INF);
for (ll e = head[supply.front()]; ~e; e = pred[e]) {
dp_pred[e] = cost[e];
}
VEVE(i, 1, SIZE(supply)) {
fill(ALL(dp_cur), INF);
VEVE(pe, 0, m) {
if (dp_pred[pe] < INF) {
VERA(best, best_edges[pe][supply[i]]) {
Min(dp_cur[best.first], dp_pred[pe] + best.second);
}
}
}
swap(dp_pred, dp_cur);
}
ll res = *min_element(ALL(dp_pred));
if (res >= INF / 2)
res = -1;
printf("%lld\n", res);
}
}
int main() {
ll tests = 1;
VEVE(test, 1, tests + 1) Solve(test);
return 0;
}
Compilation message
wild_boar.cpp: In function 'void Solve(ll)':
wild_boar.cpp:81:19: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
scanf("%d", &s);
~~^
wild_boar.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld %lld", &n, &m, &t, &l);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld", &a, &b, &c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:81:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &s);
~~~~~^~~~~~~~~~
wild_boar.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &p, &q);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
123108 KB |
Output is correct |
2 |
Correct |
113 ms |
123136 KB |
Output is correct |
3 |
Correct |
125 ms |
123168 KB |
Output is correct |
4 |
Correct |
109 ms |
123220 KB |
Output is correct |
5 |
Correct |
125 ms |
123220 KB |
Output is correct |
6 |
Correct |
122 ms |
123308 KB |
Output is correct |
7 |
Correct |
112 ms |
123308 KB |
Output is correct |
8 |
Correct |
112 ms |
123308 KB |
Output is correct |
9 |
Correct |
127 ms |
123308 KB |
Output is correct |
10 |
Correct |
122 ms |
123308 KB |
Output is correct |
11 |
Correct |
128 ms |
123308 KB |
Output is correct |
12 |
Correct |
111 ms |
123308 KB |
Output is correct |
13 |
Correct |
128 ms |
123320 KB |
Output is correct |
14 |
Correct |
113 ms |
123444 KB |
Output is correct |
15 |
Correct |
113 ms |
123444 KB |
Output is correct |
16 |
Correct |
133 ms |
123444 KB |
Output is correct |
17 |
Correct |
130 ms |
123444 KB |
Output is correct |
18 |
Correct |
107 ms |
123444 KB |
Output is correct |
19 |
Correct |
110 ms |
123444 KB |
Output is correct |
20 |
Correct |
107 ms |
123444 KB |
Output is correct |
21 |
Correct |
110 ms |
123444 KB |
Output is correct |
22 |
Correct |
116 ms |
123444 KB |
Output is correct |
23 |
Correct |
126 ms |
123444 KB |
Output is correct |
24 |
Correct |
103 ms |
123444 KB |
Output is correct |
25 |
Correct |
111 ms |
123444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
123108 KB |
Output is correct |
2 |
Correct |
113 ms |
123136 KB |
Output is correct |
3 |
Correct |
125 ms |
123168 KB |
Output is correct |
4 |
Correct |
109 ms |
123220 KB |
Output is correct |
5 |
Correct |
125 ms |
123220 KB |
Output is correct |
6 |
Correct |
122 ms |
123308 KB |
Output is correct |
7 |
Correct |
112 ms |
123308 KB |
Output is correct |
8 |
Correct |
112 ms |
123308 KB |
Output is correct |
9 |
Correct |
127 ms |
123308 KB |
Output is correct |
10 |
Correct |
122 ms |
123308 KB |
Output is correct |
11 |
Correct |
128 ms |
123308 KB |
Output is correct |
12 |
Correct |
111 ms |
123308 KB |
Output is correct |
13 |
Correct |
128 ms |
123320 KB |
Output is correct |
14 |
Correct |
113 ms |
123444 KB |
Output is correct |
15 |
Correct |
113 ms |
123444 KB |
Output is correct |
16 |
Correct |
133 ms |
123444 KB |
Output is correct |
17 |
Correct |
130 ms |
123444 KB |
Output is correct |
18 |
Correct |
107 ms |
123444 KB |
Output is correct |
19 |
Correct |
110 ms |
123444 KB |
Output is correct |
20 |
Correct |
107 ms |
123444 KB |
Output is correct |
21 |
Correct |
110 ms |
123444 KB |
Output is correct |
22 |
Correct |
116 ms |
123444 KB |
Output is correct |
23 |
Correct |
126 ms |
123444 KB |
Output is correct |
24 |
Correct |
103 ms |
123444 KB |
Output is correct |
25 |
Correct |
111 ms |
123444 KB |
Output is correct |
26 |
Correct |
112 ms |
123572 KB |
Output is correct |
27 |
Correct |
145 ms |
124540 KB |
Output is correct |
28 |
Correct |
208 ms |
124540 KB |
Output is correct |
29 |
Correct |
394 ms |
127356 KB |
Output is correct |
30 |
Correct |
343 ms |
127408 KB |
Output is correct |
31 |
Correct |
268 ms |
127408 KB |
Output is correct |
32 |
Correct |
262 ms |
127408 KB |
Output is correct |
33 |
Correct |
399 ms |
128664 KB |
Output is correct |
34 |
Correct |
361 ms |
128864 KB |
Output is correct |
35 |
Correct |
265 ms |
128864 KB |
Output is correct |
36 |
Correct |
328 ms |
128864 KB |
Output is correct |
37 |
Correct |
372 ms |
128864 KB |
Output is correct |
38 |
Correct |
393 ms |
130072 KB |
Output is correct |
39 |
Correct |
323 ms |
130288 KB |
Output is correct |
40 |
Correct |
397 ms |
130288 KB |
Output is correct |
41 |
Correct |
428 ms |
130288 KB |
Output is correct |
42 |
Correct |
298 ms |
130944 KB |
Output is correct |
43 |
Correct |
335 ms |
131484 KB |
Output is correct |
44 |
Correct |
396 ms |
131612 KB |
Output is correct |
45 |
Correct |
349 ms |
131612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
123108 KB |
Output is correct |
2 |
Correct |
113 ms |
123136 KB |
Output is correct |
3 |
Correct |
125 ms |
123168 KB |
Output is correct |
4 |
Correct |
109 ms |
123220 KB |
Output is correct |
5 |
Correct |
125 ms |
123220 KB |
Output is correct |
6 |
Correct |
122 ms |
123308 KB |
Output is correct |
7 |
Correct |
112 ms |
123308 KB |
Output is correct |
8 |
Correct |
112 ms |
123308 KB |
Output is correct |
9 |
Correct |
127 ms |
123308 KB |
Output is correct |
10 |
Correct |
122 ms |
123308 KB |
Output is correct |
11 |
Correct |
128 ms |
123308 KB |
Output is correct |
12 |
Correct |
111 ms |
123308 KB |
Output is correct |
13 |
Correct |
128 ms |
123320 KB |
Output is correct |
14 |
Correct |
113 ms |
123444 KB |
Output is correct |
15 |
Correct |
113 ms |
123444 KB |
Output is correct |
16 |
Correct |
133 ms |
123444 KB |
Output is correct |
17 |
Correct |
130 ms |
123444 KB |
Output is correct |
18 |
Correct |
107 ms |
123444 KB |
Output is correct |
19 |
Correct |
110 ms |
123444 KB |
Output is correct |
20 |
Correct |
107 ms |
123444 KB |
Output is correct |
21 |
Correct |
110 ms |
123444 KB |
Output is correct |
22 |
Correct |
116 ms |
123444 KB |
Output is correct |
23 |
Correct |
126 ms |
123444 KB |
Output is correct |
24 |
Correct |
103 ms |
123444 KB |
Output is correct |
25 |
Correct |
111 ms |
123444 KB |
Output is correct |
26 |
Correct |
112 ms |
123572 KB |
Output is correct |
27 |
Correct |
145 ms |
124540 KB |
Output is correct |
28 |
Correct |
208 ms |
124540 KB |
Output is correct |
29 |
Correct |
394 ms |
127356 KB |
Output is correct |
30 |
Correct |
343 ms |
127408 KB |
Output is correct |
31 |
Correct |
268 ms |
127408 KB |
Output is correct |
32 |
Correct |
262 ms |
127408 KB |
Output is correct |
33 |
Correct |
399 ms |
128664 KB |
Output is correct |
34 |
Correct |
361 ms |
128864 KB |
Output is correct |
35 |
Correct |
265 ms |
128864 KB |
Output is correct |
36 |
Correct |
328 ms |
128864 KB |
Output is correct |
37 |
Correct |
372 ms |
128864 KB |
Output is correct |
38 |
Correct |
393 ms |
130072 KB |
Output is correct |
39 |
Correct |
323 ms |
130288 KB |
Output is correct |
40 |
Correct |
397 ms |
130288 KB |
Output is correct |
41 |
Correct |
428 ms |
130288 KB |
Output is correct |
42 |
Correct |
298 ms |
130944 KB |
Output is correct |
43 |
Correct |
335 ms |
131484 KB |
Output is correct |
44 |
Correct |
396 ms |
131612 KB |
Output is correct |
45 |
Correct |
349 ms |
131612 KB |
Output is correct |
46 |
Correct |
339 ms |
133016 KB |
Output is correct |
47 |
Runtime error |
2130 ms |
364004 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
123108 KB |
Output is correct |
2 |
Correct |
113 ms |
123136 KB |
Output is correct |
3 |
Correct |
125 ms |
123168 KB |
Output is correct |
4 |
Correct |
109 ms |
123220 KB |
Output is correct |
5 |
Correct |
125 ms |
123220 KB |
Output is correct |
6 |
Correct |
122 ms |
123308 KB |
Output is correct |
7 |
Correct |
112 ms |
123308 KB |
Output is correct |
8 |
Correct |
112 ms |
123308 KB |
Output is correct |
9 |
Correct |
127 ms |
123308 KB |
Output is correct |
10 |
Correct |
122 ms |
123308 KB |
Output is correct |
11 |
Correct |
128 ms |
123308 KB |
Output is correct |
12 |
Correct |
111 ms |
123308 KB |
Output is correct |
13 |
Correct |
128 ms |
123320 KB |
Output is correct |
14 |
Correct |
113 ms |
123444 KB |
Output is correct |
15 |
Correct |
113 ms |
123444 KB |
Output is correct |
16 |
Correct |
133 ms |
123444 KB |
Output is correct |
17 |
Correct |
130 ms |
123444 KB |
Output is correct |
18 |
Correct |
107 ms |
123444 KB |
Output is correct |
19 |
Correct |
110 ms |
123444 KB |
Output is correct |
20 |
Correct |
107 ms |
123444 KB |
Output is correct |
21 |
Correct |
110 ms |
123444 KB |
Output is correct |
22 |
Correct |
116 ms |
123444 KB |
Output is correct |
23 |
Correct |
126 ms |
123444 KB |
Output is correct |
24 |
Correct |
103 ms |
123444 KB |
Output is correct |
25 |
Correct |
111 ms |
123444 KB |
Output is correct |
26 |
Correct |
112 ms |
123572 KB |
Output is correct |
27 |
Correct |
145 ms |
124540 KB |
Output is correct |
28 |
Correct |
208 ms |
124540 KB |
Output is correct |
29 |
Correct |
394 ms |
127356 KB |
Output is correct |
30 |
Correct |
343 ms |
127408 KB |
Output is correct |
31 |
Correct |
268 ms |
127408 KB |
Output is correct |
32 |
Correct |
262 ms |
127408 KB |
Output is correct |
33 |
Correct |
399 ms |
128664 KB |
Output is correct |
34 |
Correct |
361 ms |
128864 KB |
Output is correct |
35 |
Correct |
265 ms |
128864 KB |
Output is correct |
36 |
Correct |
328 ms |
128864 KB |
Output is correct |
37 |
Correct |
372 ms |
128864 KB |
Output is correct |
38 |
Correct |
393 ms |
130072 KB |
Output is correct |
39 |
Correct |
323 ms |
130288 KB |
Output is correct |
40 |
Correct |
397 ms |
130288 KB |
Output is correct |
41 |
Correct |
428 ms |
130288 KB |
Output is correct |
42 |
Correct |
298 ms |
130944 KB |
Output is correct |
43 |
Correct |
335 ms |
131484 KB |
Output is correct |
44 |
Correct |
396 ms |
131612 KB |
Output is correct |
45 |
Correct |
349 ms |
131612 KB |
Output is correct |
46 |
Correct |
339 ms |
133016 KB |
Output is correct |
47 |
Runtime error |
2130 ms |
364004 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
48 |
Halted |
0 ms |
0 KB |
- |