#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 = INF + d1[n], mid;
while (lo < hi) {
mid = lo + hi + 1 >> 1;
if (isPos(mid)) {
lo = mid;
} else {
hi = mid - 1;
}
}
printf("%lld\n", lo + 1);
return 0;
}
Compilation message
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:114:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
114 | mid = lo + hi + 1 >> 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]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8524 KB |
Output is correct |
2 |
Correct |
6 ms |
8524 KB |
Output is correct |
3 |
Correct |
6 ms |
8524 KB |
Output is correct |
4 |
Correct |
6 ms |
8528 KB |
Output is correct |
5 |
Correct |
5 ms |
8524 KB |
Output is correct |
6 |
Correct |
6 ms |
8452 KB |
Output is correct |
7 |
Correct |
6 ms |
8524 KB |
Output is correct |
8 |
Correct |
8 ms |
8524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8524 KB |
Output is correct |
2 |
Correct |
6 ms |
8524 KB |
Output is correct |
3 |
Correct |
6 ms |
8524 KB |
Output is correct |
4 |
Correct |
6 ms |
8528 KB |
Output is correct |
5 |
Correct |
5 ms |
8524 KB |
Output is correct |
6 |
Correct |
6 ms |
8452 KB |
Output is correct |
7 |
Correct |
6 ms |
8524 KB |
Output is correct |
8 |
Correct |
8 ms |
8524 KB |
Output is correct |
9 |
Correct |
7 ms |
8720 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 |
8652 KB |
Output is correct |
13 |
Correct |
7 ms |
8652 KB |
Output is correct |
14 |
Correct |
8 ms |
8652 KB |
Output is correct |
15 |
Correct |
7 ms |
8684 KB |
Output is correct |
16 |
Correct |
7 ms |
8652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
400 ms |
31212 KB |
Output is correct |
2 |
Correct |
400 ms |
31328 KB |
Output is correct |
3 |
Correct |
389 ms |
31192 KB |
Output is correct |
4 |
Correct |
429 ms |
31044 KB |
Output is correct |
5 |
Correct |
380 ms |
31212 KB |
Output is correct |
6 |
Correct |
414 ms |
31732 KB |
Output is correct |
7 |
Correct |
395 ms |
31520 KB |
Output is correct |
8 |
Correct |
430 ms |
31692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
397 ms |
31740 KB |
Output is correct |
2 |
Correct |
442 ms |
31376 KB |
Output is correct |
3 |
Correct |
384 ms |
30944 KB |
Output is correct |
4 |
Correct |
404 ms |
31112 KB |
Output is correct |
5 |
Correct |
403 ms |
31200 KB |
Output is correct |
6 |
Correct |
435 ms |
31324 KB |
Output is correct |
7 |
Correct |
398 ms |
31300 KB |
Output is correct |
8 |
Correct |
413 ms |
31544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1872 ms |
38612 KB |
Output is correct |
2 |
Correct |
739 ms |
28140 KB |
Output is correct |
3 |
Incorrect |
889 ms |
33792 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1872 ms |
38612 KB |
Output is correct |
2 |
Correct |
739 ms |
28140 KB |
Output is correct |
3 |
Incorrect |
889 ms |
33792 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8524 KB |
Output is correct |
2 |
Correct |
6 ms |
8524 KB |
Output is correct |
3 |
Correct |
6 ms |
8524 KB |
Output is correct |
4 |
Correct |
6 ms |
8528 KB |
Output is correct |
5 |
Correct |
5 ms |
8524 KB |
Output is correct |
6 |
Correct |
6 ms |
8452 KB |
Output is correct |
7 |
Correct |
6 ms |
8524 KB |
Output is correct |
8 |
Correct |
8 ms |
8524 KB |
Output is correct |
9 |
Correct |
7 ms |
8720 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 |
8652 KB |
Output is correct |
13 |
Correct |
7 ms |
8652 KB |
Output is correct |
14 |
Correct |
8 ms |
8652 KB |
Output is correct |
15 |
Correct |
7 ms |
8684 KB |
Output is correct |
16 |
Correct |
7 ms |
8652 KB |
Output is correct |
17 |
Correct |
400 ms |
31212 KB |
Output is correct |
18 |
Correct |
400 ms |
31328 KB |
Output is correct |
19 |
Correct |
389 ms |
31192 KB |
Output is correct |
20 |
Correct |
429 ms |
31044 KB |
Output is correct |
21 |
Correct |
380 ms |
31212 KB |
Output is correct |
22 |
Correct |
414 ms |
31732 KB |
Output is correct |
23 |
Correct |
395 ms |
31520 KB |
Output is correct |
24 |
Correct |
430 ms |
31692 KB |
Output is correct |
25 |
Correct |
397 ms |
31740 KB |
Output is correct |
26 |
Correct |
442 ms |
31376 KB |
Output is correct |
27 |
Correct |
384 ms |
30944 KB |
Output is correct |
28 |
Correct |
404 ms |
31112 KB |
Output is correct |
29 |
Correct |
403 ms |
31200 KB |
Output is correct |
30 |
Correct |
435 ms |
31324 KB |
Output is correct |
31 |
Correct |
398 ms |
31300 KB |
Output is correct |
32 |
Correct |
413 ms |
31544 KB |
Output is correct |
33 |
Correct |
1872 ms |
38612 KB |
Output is correct |
34 |
Correct |
739 ms |
28140 KB |
Output is correct |
35 |
Incorrect |
889 ms |
33792 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |