#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
#ifdef DEBUG
#define debug(args...) printf(args)
#else
#define debug(args...)
#endif
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 300005
struct edge {
int v, w, p;
};
int n, m;
vector<edge> adj[MAXN];
int a[MAXN], b[MAXN], w[MAXN], p[MAXN];
priority_queue<pll, vector<pll>, greater<pll>> pq;
ll d1[MAXN], dn[MAXN];
void dij(int s, ll* d) {
REP (i, 1, n + 1) {
d[i] = LINF;
}
d[s] = 0;
pq.push(MP(0, s));
while (!pq.empty()) {
auto [ud, u] = pq.top(); pq.pop();
if (ud != d[u]) continue;
for (edge e : adj[u]) {
if (mnto(d[e.v], ud + e.w)) {
pq.push(MP(d[e.v], e.v));
}
}
}
}
ll x;
bool res;
int dep[MAXN], low[MAXN], ptr;
void dfs(int u, int p) {
dep[u] = low[u] = ptr++;
for (edge e : adj[u]) {
if (e.v == p) continue;
ll od = min(d1[u] + dn[e.v], d1[e.v] + dn[u]) + e.w;
if (od > x) continue;
if (dep[e.v] == -1) {
dfs(e.v, u);
if (res) return;
mnto(low[u], low[e.v]);
if (low[e.v] > dep[u] && od + e.p > x &&
dep[n] != -1 && dep[n] >= low[e.v]) {
res = 1;
return;
}
} else {
mnto(low[u], dep[e.v]);
}
}
}
bool isPos(ll x) {
ptr = 0;
::x = x;
res = 0;
memset(dep, -1, sizeof dep);
dfs(1, -1);
return res;
}
int main() {
scanf("%d%d", &n, &m);
REP (i, 0, m) {
scanf("%d%d%d", &a[i], &b[i], &w[i]);
}
int mx = 0;
RREP (i, m - 1, 0) {
p[i] = mx;
mxto(mx, w[i]);
}
REP (i, 0, m) {
adj[a[i]].pb({b[i], w[i], p[i]});
adj[b[i]].pb({a[i], w[i], p[i]});
}
dij(1, d1);
dij(n, dn);
ll lo = d1[n], hi = p[0] + d1[n] + 5, mid;
while (lo < hi) {
mid = lo + hi >> 1;
if (isPos(mid)) {
debug("Hi\n");
lo = mid + 1;
} else {
hi = mid;
}
}
printf("%lld\n", lo);
return 0;
}
Compilation message
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:114:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
114 | mid = lo + hi >> 1;
| ~~~^~~~
Aesthetic.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
Aesthetic.cpp:99:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | scanf("%d%d%d", &a[i], &b[i], &w[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8524 KB |
Output is correct |
2 |
Correct |
6 ms |
8480 KB |
Output is correct |
3 |
Correct |
6 ms |
8524 KB |
Output is correct |
4 |
Correct |
6 ms |
8504 KB |
Output is correct |
5 |
Correct |
6 ms |
8524 KB |
Output is correct |
6 |
Correct |
7 ms |
8568 KB |
Output is correct |
7 |
Correct |
7 ms |
8524 KB |
Output is correct |
8 |
Correct |
6 ms |
8524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8524 KB |
Output is correct |
2 |
Correct |
6 ms |
8480 KB |
Output is correct |
3 |
Correct |
6 ms |
8524 KB |
Output is correct |
4 |
Correct |
6 ms |
8504 KB |
Output is correct |
5 |
Correct |
6 ms |
8524 KB |
Output is correct |
6 |
Correct |
7 ms |
8568 KB |
Output is correct |
7 |
Correct |
7 ms |
8524 KB |
Output is correct |
8 |
Correct |
6 ms |
8524 KB |
Output is correct |
9 |
Correct |
7 ms |
8652 KB |
Output is correct |
10 |
Correct |
7 ms |
8652 KB |
Output is correct |
11 |
Correct |
7 ms |
8652 KB |
Output is correct |
12 |
Correct |
8 ms |
8648 KB |
Output is correct |
13 |
Correct |
7 ms |
8780 KB |
Output is correct |
14 |
Correct |
7 ms |
8780 KB |
Output is correct |
15 |
Correct |
7 ms |
8776 KB |
Output is correct |
16 |
Correct |
7 ms |
8668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
395 ms |
33928 KB |
Output is correct |
2 |
Correct |
412 ms |
32884 KB |
Output is correct |
3 |
Correct |
402 ms |
32568 KB |
Output is correct |
4 |
Correct |
403 ms |
32456 KB |
Output is correct |
5 |
Correct |
449 ms |
32604 KB |
Output is correct |
6 |
Correct |
432 ms |
33128 KB |
Output is correct |
7 |
Correct |
425 ms |
32912 KB |
Output is correct |
8 |
Correct |
409 ms |
33152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
450 ms |
34384 KB |
Output is correct |
2 |
Correct |
414 ms |
32848 KB |
Output is correct |
3 |
Correct |
419 ms |
32440 KB |
Output is correct |
4 |
Correct |
408 ms |
32440 KB |
Output is correct |
5 |
Correct |
422 ms |
32708 KB |
Output is correct |
6 |
Correct |
407 ms |
32792 KB |
Output is correct |
7 |
Correct |
406 ms |
32708 KB |
Output is correct |
8 |
Correct |
419 ms |
32964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
387 ms |
32968 KB |
Output is correct |
2 |
Correct |
187 ms |
29180 KB |
Output is correct |
3 |
Correct |
263 ms |
35068 KB |
Output is correct |
4 |
Correct |
278 ms |
37672 KB |
Output is correct |
5 |
Correct |
274 ms |
37572 KB |
Output is correct |
6 |
Correct |
301 ms |
37700 KB |
Output is correct |
7 |
Correct |
264 ms |
37752 KB |
Output is correct |
8 |
Correct |
283 ms |
38148 KB |
Output is correct |
9 |
Correct |
281 ms |
37668 KB |
Output is correct |
10 |
Correct |
281 ms |
38148 KB |
Output is correct |
11 |
Correct |
285 ms |
37716 KB |
Output is correct |
12 |
Correct |
321 ms |
34276 KB |
Output is correct |
13 |
Correct |
265 ms |
37752 KB |
Output is correct |
14 |
Correct |
148 ms |
49600 KB |
Output is correct |
15 |
Correct |
163 ms |
49636 KB |
Output is correct |
16 |
Correct |
353 ms |
34704 KB |
Output is correct |
17 |
Correct |
327 ms |
34172 KB |
Output is correct |
18 |
Correct |
326 ms |
34180 KB |
Output is correct |
19 |
Correct |
187 ms |
32176 KB |
Output is correct |
20 |
Correct |
184 ms |
32352 KB |
Output is correct |
21 |
Correct |
185 ms |
32216 KB |
Output is correct |
22 |
Correct |
187 ms |
32176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
387 ms |
32968 KB |
Output is correct |
2 |
Correct |
187 ms |
29180 KB |
Output is correct |
3 |
Correct |
263 ms |
35068 KB |
Output is correct |
4 |
Correct |
278 ms |
37672 KB |
Output is correct |
5 |
Correct |
274 ms |
37572 KB |
Output is correct |
6 |
Correct |
301 ms |
37700 KB |
Output is correct |
7 |
Correct |
264 ms |
37752 KB |
Output is correct |
8 |
Correct |
283 ms |
38148 KB |
Output is correct |
9 |
Correct |
281 ms |
37668 KB |
Output is correct |
10 |
Correct |
281 ms |
38148 KB |
Output is correct |
11 |
Correct |
285 ms |
37716 KB |
Output is correct |
12 |
Correct |
321 ms |
34276 KB |
Output is correct |
13 |
Correct |
265 ms |
37752 KB |
Output is correct |
14 |
Correct |
148 ms |
49600 KB |
Output is correct |
15 |
Correct |
163 ms |
49636 KB |
Output is correct |
16 |
Correct |
353 ms |
34704 KB |
Output is correct |
17 |
Correct |
327 ms |
34172 KB |
Output is correct |
18 |
Correct |
326 ms |
34180 KB |
Output is correct |
19 |
Correct |
187 ms |
32176 KB |
Output is correct |
20 |
Correct |
184 ms |
32352 KB |
Output is correct |
21 |
Correct |
185 ms |
32216 KB |
Output is correct |
22 |
Correct |
187 ms |
32176 KB |
Output is correct |
23 |
Correct |
383 ms |
34928 KB |
Output is correct |
24 |
Correct |
238 ms |
32304 KB |
Output is correct |
25 |
Correct |
225 ms |
35844 KB |
Output is correct |
26 |
Correct |
231 ms |
35040 KB |
Output is correct |
27 |
Correct |
231 ms |
35016 KB |
Output is correct |
28 |
Correct |
229 ms |
36084 KB |
Output is correct |
29 |
Correct |
230 ms |
35340 KB |
Output is correct |
30 |
Correct |
226 ms |
35460 KB |
Output is correct |
31 |
Correct |
220 ms |
35684 KB |
Output is correct |
32 |
Correct |
238 ms |
35264 KB |
Output is correct |
33 |
Correct |
241 ms |
35924 KB |
Output is correct |
34 |
Correct |
346 ms |
34312 KB |
Output is correct |
35 |
Correct |
235 ms |
35504 KB |
Output is correct |
36 |
Correct |
171 ms |
47080 KB |
Output is correct |
37 |
Correct |
175 ms |
47728 KB |
Output is correct |
38 |
Correct |
400 ms |
34604 KB |
Output is correct |
39 |
Correct |
350 ms |
34028 KB |
Output is correct |
40 |
Correct |
386 ms |
34836 KB |
Output is correct |
41 |
Correct |
223 ms |
32464 KB |
Output is correct |
42 |
Correct |
215 ms |
32308 KB |
Output is correct |
43 |
Correct |
242 ms |
32280 KB |
Output is correct |
44 |
Correct |
240 ms |
32324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8524 KB |
Output is correct |
2 |
Correct |
6 ms |
8480 KB |
Output is correct |
3 |
Correct |
6 ms |
8524 KB |
Output is correct |
4 |
Correct |
6 ms |
8504 KB |
Output is correct |
5 |
Correct |
6 ms |
8524 KB |
Output is correct |
6 |
Correct |
7 ms |
8568 KB |
Output is correct |
7 |
Correct |
7 ms |
8524 KB |
Output is correct |
8 |
Correct |
6 ms |
8524 KB |
Output is correct |
9 |
Correct |
7 ms |
8652 KB |
Output is correct |
10 |
Correct |
7 ms |
8652 KB |
Output is correct |
11 |
Correct |
7 ms |
8652 KB |
Output is correct |
12 |
Correct |
8 ms |
8648 KB |
Output is correct |
13 |
Correct |
7 ms |
8780 KB |
Output is correct |
14 |
Correct |
7 ms |
8780 KB |
Output is correct |
15 |
Correct |
7 ms |
8776 KB |
Output is correct |
16 |
Correct |
7 ms |
8668 KB |
Output is correct |
17 |
Correct |
395 ms |
33928 KB |
Output is correct |
18 |
Correct |
412 ms |
32884 KB |
Output is correct |
19 |
Correct |
402 ms |
32568 KB |
Output is correct |
20 |
Correct |
403 ms |
32456 KB |
Output is correct |
21 |
Correct |
449 ms |
32604 KB |
Output is correct |
22 |
Correct |
432 ms |
33128 KB |
Output is correct |
23 |
Correct |
425 ms |
32912 KB |
Output is correct |
24 |
Correct |
409 ms |
33152 KB |
Output is correct |
25 |
Correct |
450 ms |
34384 KB |
Output is correct |
26 |
Correct |
414 ms |
32848 KB |
Output is correct |
27 |
Correct |
419 ms |
32440 KB |
Output is correct |
28 |
Correct |
408 ms |
32440 KB |
Output is correct |
29 |
Correct |
422 ms |
32708 KB |
Output is correct |
30 |
Correct |
407 ms |
32792 KB |
Output is correct |
31 |
Correct |
406 ms |
32708 KB |
Output is correct |
32 |
Correct |
419 ms |
32964 KB |
Output is correct |
33 |
Correct |
387 ms |
32968 KB |
Output is correct |
34 |
Correct |
187 ms |
29180 KB |
Output is correct |
35 |
Correct |
263 ms |
35068 KB |
Output is correct |
36 |
Correct |
278 ms |
37672 KB |
Output is correct |
37 |
Correct |
274 ms |
37572 KB |
Output is correct |
38 |
Correct |
301 ms |
37700 KB |
Output is correct |
39 |
Correct |
264 ms |
37752 KB |
Output is correct |
40 |
Correct |
283 ms |
38148 KB |
Output is correct |
41 |
Correct |
281 ms |
37668 KB |
Output is correct |
42 |
Correct |
281 ms |
38148 KB |
Output is correct |
43 |
Correct |
285 ms |
37716 KB |
Output is correct |
44 |
Correct |
321 ms |
34276 KB |
Output is correct |
45 |
Correct |
265 ms |
37752 KB |
Output is correct |
46 |
Correct |
148 ms |
49600 KB |
Output is correct |
47 |
Correct |
163 ms |
49636 KB |
Output is correct |
48 |
Correct |
353 ms |
34704 KB |
Output is correct |
49 |
Correct |
327 ms |
34172 KB |
Output is correct |
50 |
Correct |
326 ms |
34180 KB |
Output is correct |
51 |
Correct |
187 ms |
32176 KB |
Output is correct |
52 |
Correct |
184 ms |
32352 KB |
Output is correct |
53 |
Correct |
185 ms |
32216 KB |
Output is correct |
54 |
Correct |
187 ms |
32176 KB |
Output is correct |
55 |
Correct |
383 ms |
34928 KB |
Output is correct |
56 |
Correct |
238 ms |
32304 KB |
Output is correct |
57 |
Correct |
225 ms |
35844 KB |
Output is correct |
58 |
Correct |
231 ms |
35040 KB |
Output is correct |
59 |
Correct |
231 ms |
35016 KB |
Output is correct |
60 |
Correct |
229 ms |
36084 KB |
Output is correct |
61 |
Correct |
230 ms |
35340 KB |
Output is correct |
62 |
Correct |
226 ms |
35460 KB |
Output is correct |
63 |
Correct |
220 ms |
35684 KB |
Output is correct |
64 |
Correct |
238 ms |
35264 KB |
Output is correct |
65 |
Correct |
241 ms |
35924 KB |
Output is correct |
66 |
Correct |
346 ms |
34312 KB |
Output is correct |
67 |
Correct |
235 ms |
35504 KB |
Output is correct |
68 |
Correct |
171 ms |
47080 KB |
Output is correct |
69 |
Correct |
175 ms |
47728 KB |
Output is correct |
70 |
Correct |
400 ms |
34604 KB |
Output is correct |
71 |
Correct |
350 ms |
34028 KB |
Output is correct |
72 |
Correct |
386 ms |
34836 KB |
Output is correct |
73 |
Correct |
223 ms |
32464 KB |
Output is correct |
74 |
Correct |
215 ms |
32308 KB |
Output is correct |
75 |
Correct |
242 ms |
32280 KB |
Output is correct |
76 |
Correct |
240 ms |
32324 KB |
Output is correct |
77 |
Correct |
404 ms |
37316 KB |
Output is correct |
78 |
Correct |
409 ms |
34568 KB |
Output is correct |
79 |
Correct |
292 ms |
40044 KB |
Output is correct |
80 |
Correct |
297 ms |
39988 KB |
Output is correct |
81 |
Correct |
353 ms |
39920 KB |
Output is correct |
82 |
Correct |
298 ms |
39780 KB |
Output is correct |
83 |
Correct |
294 ms |
40448 KB |
Output is correct |
84 |
Correct |
337 ms |
40280 KB |
Output is correct |
85 |
Correct |
303 ms |
40004 KB |
Output is correct |
86 |
Correct |
298 ms |
40072 KB |
Output is correct |
87 |
Correct |
311 ms |
40256 KB |
Output is correct |
88 |
Correct |
405 ms |
36620 KB |
Output is correct |
89 |
Correct |
315 ms |
40128 KB |
Output is correct |
90 |
Correct |
256 ms |
47848 KB |
Output is correct |
91 |
Correct |
267 ms |
48360 KB |
Output is correct |
92 |
Correct |
443 ms |
36848 KB |
Output is correct |
93 |
Correct |
423 ms |
36512 KB |
Output is correct |
94 |
Correct |
457 ms |
36068 KB |
Output is correct |
95 |
Correct |
388 ms |
34508 KB |
Output is correct |
96 |
Correct |
388 ms |
34688 KB |
Output is correct |
97 |
Correct |
406 ms |
34632 KB |
Output is correct |
98 |
Correct |
374 ms |
34564 KB |
Output is correct |