#include <bits/stdc++.h>
using namespace std;
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; }
template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; }
const int MAXN = 2e5 + 5;
int N, M, a[MAXN], dpL[MAXN], dpR[MAXN];
vector <int> adj[MAXN];
void dijkstra(int s, int dp[]) {
fill(dp + 1, dp + N + 1, 1e9);
dp[s] = a[s];
priority_queue <pair <int, int>, vector <pair <int, int>>, greater_equal <pair <int, int>>> q;
q.emplace(dp[s], s);
while(q.size()) {
auto [du, u] = q.top(); q.pop();
if(dp[u] != du) continue;
for (auto v : adj[u]) if(minimize(dp[v], max(dp[u] + 1, a[v]))) {
q.emplace(dp[v], v);
}
}
}
void you_make_it(void) {
cin >> N >> M;
FOR(i, 1, N) cin >> a[i];
while(M--) {
int u, v; cin >> u >> v;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
int res = 2e9;
dijkstra(1, dpL);
dijkstra(N, dpR);
FOR(i, 1, N) {
minimize(res, 2 * max(dpL[i], dpR[i]));
}
// FOR(i, 1, N) cout << dpL[i] << " \n"[i == N];
// FOR(i, 1, N) cout << dpR[i] << " \n"[i == N];
FOR(u, 1, N) for (auto v : adj[u]) {
minimize(res, 2 * max(dpL[u], dpR[v]) + 1);
}
cout << res;
}
signed main() {
#ifdef LOCAL
freopen("TASK.inp", "r", stdin);
freopen("TASK.out", "w", stdout);
#endif
file("airplane");
auto start_time = chrono::steady_clock::now();
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
you_make_it();
auto end_time = chrono::steady_clock::now();
cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;
return (0 ^ 0);
}
// Dream it. Wish it. Do it.
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:13:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:66:4: note: in expansion of macro 'file'
66 | file("airplane");
| ^~~~
Main.cpp:13:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:66:4: note: in expansion of macro 'file'
66 | file("airplane");
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
54 ms |
16860 KB |
Output is correct |
3 |
Correct |
56 ms |
17268 KB |
Output is correct |
4 |
Correct |
57 ms |
17392 KB |
Output is correct |
5 |
Correct |
64 ms |
17812 KB |
Output is correct |
6 |
Correct |
59 ms |
18000 KB |
Output is correct |
7 |
Correct |
58 ms |
17948 KB |
Output is correct |
8 |
Correct |
1 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
2 ms |
6744 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
3 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
3 ms |
6748 KB |
Output is correct |
15 |
Correct |
3 ms |
6748 KB |
Output is correct |
16 |
Correct |
3 ms |
6880 KB |
Output is correct |
17 |
Correct |
3 ms |
6916 KB |
Output is correct |
18 |
Correct |
1 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
2 ms |
6744 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
3 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
3 ms |
6748 KB |
Output is correct |
15 |
Correct |
3 ms |
6748 KB |
Output is correct |
16 |
Correct |
3 ms |
6880 KB |
Output is correct |
17 |
Correct |
3 ms |
6916 KB |
Output is correct |
18 |
Correct |
1 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
3 ms |
6828 KB |
Output is correct |
21 |
Correct |
2 ms |
6744 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6748 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
2 ms |
6748 KB |
Output is correct |
27 |
Correct |
3 ms |
6764 KB |
Output is correct |
28 |
Correct |
4 ms |
6748 KB |
Output is correct |
29 |
Correct |
3 ms |
6748 KB |
Output is correct |
30 |
Correct |
4 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
54 ms |
16860 KB |
Output is correct |
3 |
Correct |
56 ms |
17268 KB |
Output is correct |
4 |
Correct |
57 ms |
17392 KB |
Output is correct |
5 |
Correct |
64 ms |
17812 KB |
Output is correct |
6 |
Correct |
59 ms |
18000 KB |
Output is correct |
7 |
Correct |
58 ms |
17948 KB |
Output is correct |
8 |
Correct |
1 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
7004 KB |
Output is correct |
11 |
Correct |
2 ms |
6744 KB |
Output is correct |
12 |
Correct |
1 ms |
6748 KB |
Output is correct |
13 |
Correct |
1 ms |
6748 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6744 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
3 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
3 ms |
6748 KB |
Output is correct |
23 |
Correct |
3 ms |
6748 KB |
Output is correct |
24 |
Correct |
3 ms |
6880 KB |
Output is correct |
25 |
Correct |
3 ms |
6916 KB |
Output is correct |
26 |
Correct |
1 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
3 ms |
6828 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
30 |
Correct |
2 ms |
6748 KB |
Output is correct |
31 |
Correct |
2 ms |
6748 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
2 ms |
6748 KB |
Output is correct |
35 |
Correct |
3 ms |
6764 KB |
Output is correct |
36 |
Correct |
4 ms |
6748 KB |
Output is correct |
37 |
Correct |
3 ms |
6748 KB |
Output is correct |
38 |
Correct |
4 ms |
6748 KB |
Output is correct |
39 |
Correct |
167 ms |
18260 KB |
Output is correct |
40 |
Correct |
83 ms |
17236 KB |
Output is correct |
41 |
Correct |
111 ms |
17032 KB |
Output is correct |
42 |
Correct |
103 ms |
17236 KB |
Output is correct |
43 |
Correct |
99 ms |
17236 KB |
Output is correct |
44 |
Correct |
86 ms |
17132 KB |
Output is correct |
45 |
Correct |
103 ms |
17156 KB |
Output is correct |
46 |
Correct |
102 ms |
17236 KB |
Output is correct |
47 |
Correct |
110 ms |
17232 KB |
Output is correct |
48 |
Correct |
90 ms |
16980 KB |
Output is correct |
49 |
Correct |
132 ms |
18004 KB |
Output is correct |
50 |
Correct |
135 ms |
17880 KB |
Output is correct |
51 |
Correct |
103 ms |
17744 KB |
Output is correct |
52 |
Correct |
241 ms |
20912 KB |
Output is correct |
53 |
Correct |
172 ms |
19712 KB |
Output is correct |
54 |
Correct |
146 ms |
19592 KB |
Output is correct |
55 |
Correct |
291 ms |
19892 KB |
Output is correct |
56 |
Correct |
228 ms |
22856 KB |
Output is correct |
57 |
Correct |
209 ms |
23180 KB |
Output is correct |
58 |
Correct |
270 ms |
24544 KB |
Output is correct |
59 |
Correct |
225 ms |
24328 KB |
Output is correct |
60 |
Correct |
214 ms |
23884 KB |
Output is correct |
61 |
Correct |
271 ms |
23700 KB |
Output is correct |
62 |
Correct |
240 ms |
22864 KB |
Output is correct |
63 |
Correct |
194 ms |
22840 KB |
Output is correct |
64 |
Correct |
235 ms |
22884 KB |
Output is correct |
65 |
Correct |
242 ms |
23148 KB |
Output is correct |
66 |
Correct |
246 ms |
23232 KB |
Output is correct |
67 |
Correct |
193 ms |
23104 KB |
Output is correct |