Submission #892699

# Submission time Handle Problem Language Result Execution time Memory
892699 2023-12-25T17:15:00 Z CDuong Aesthetic (NOI20_aesthetic) C++17
100 / 100
1642 ms 65384 KB
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;

const int mxN = 3e5 + 5;
const int mxM = 3e5 + 5;
const int mod = 1e9 + 7;
const i64 oo = 1e18;

int n, m;
bool vis[mxN];
vector<pair<int, int>> G[mxN], Gn[mxN];
int w[mxM], max_w[mxM];
i64 dis1[mxN], disn[mxN];
pair<int, int> edges[mxM];

i64 dijkstra() {
    fill(dis1 + 1, dis1 + n + 1, oo);
    priority_queue<pair<i64, int>, vector<pair<i64, int>>, greater<pair<i64, int>>> pq;

    dis1[1] = 0; pq.emplace(0, 1);
    while (not pq.empty()) {
        i64 cdis = pq.top().ff;
        int v = pq.top().ss;
        pq.pop();
        if (cdis != dis1[v]) continue;
        for (auto [u, ei] : G[v]) {
            if (dis1[v] + w[ei] < dis1[u]) {
                dis1[u] = dis1[v] + w[ei];
                pq.emplace(dis1[u], u);
            }
        }
    }

    fill(disn + 1, disn + n + 1, oo);
    disn[n] = 0; pq.emplace(0, n);
    while (not pq.empty()) {
        i64 cdis = pq.top().ff;
        int v = pq.top().ss;
        pq.pop();
        if (cdis != disn[v]) continue;
        for (auto [u, ei] : G[v]) {
            if (disn[v] + w[ei] < disn[u]) {
                disn[u] = disn[v] + w[ei];
                pq.emplace(disn[u], u);
            }
        }
    }

    return dis1[n];
}

i64 res_check;
bool vis_n[mxN];
int low[mxN], tin[mxN], tdfs;

void reset_check() {
    res_check = -1, tdfs = 0;
    for (int i = 1; i <= n; ++i) {
        G[i].clear();
        vis[i] = vis_n[i] = false;
    }
}

void dfs(int v, int p) {
    vis[v] = true, vis_n[v] = (v == n);
    tin[v] = low[v] = ++tdfs;
    for (auto [u, ei] : G[v]) {
        if (u == p) continue;
        if (vis[u]) {
            low[v] = min(low[v], tin[u]);
        }
        else {
            dfs(u, v);
            low[v] = min(low[v], low[u]);
            if (low[u] > tin[v] && vis_n[u]) {
                res_check = max(res_check, min(dis1[u] + disn[v], dis1[v] + disn[u]) + w[ei] + max_w[ei]);
            }
            vis_n[v] |= vis_n[u];
        }
    }
}

bool check(i64 val) {
    reset_check();
    for (int i = 1; i <= m; ++i) {
        int u = edges[i].ff, v = edges[i].ss;
        if (min(dis1[u] + disn[v], dis1[v] + disn[u]) + w[i] <= val) {
            // cout << u << " " << v << endl;
            G[u].emplace_back(v, i);
            G[v].emplace_back(u, i);
        }
    }
    dfs(1, 0);
    // cout << res_check << endl << endl;
    return !(res_check > val);
}

void solve() {
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int u, v, cw;
        cin >> u >> v >> cw;
        G[u].emplace_back(v, i);
        G[v].emplace_back(u, i);
        edges[i] = {u, v};
        w[i] = max_w[i - 1] = cw;
    }
    for (int i = m - 1; i >= 1; --i)
        max_w[i] = max(max_w[i], max_w[i + 1]);

    i64 miin = dijkstra();
    i64 l = miin, r = miin + 1e9;
    while (l < r) {
        i64 mid = (l + r) >> 1;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }
    cout << l << endl;
}

signed main() {

#ifndef CDuongg
    if(fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
   auto end = chrono::high_resolution_clock::now();
   cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
   cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
   cout << "Check array size pls sir" << endl;
#endif

}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 27224 KB Output is correct
2 Correct 5 ms 27224 KB Output is correct
3 Correct 5 ms 27228 KB Output is correct
4 Correct 5 ms 27056 KB Output is correct
5 Correct 5 ms 27228 KB Output is correct
6 Correct 5 ms 27280 KB Output is correct
7 Correct 5 ms 27228 KB Output is correct
8 Correct 5 ms 27484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 27224 KB Output is correct
2 Correct 5 ms 27224 KB Output is correct
3 Correct 5 ms 27228 KB Output is correct
4 Correct 5 ms 27056 KB Output is correct
5 Correct 5 ms 27228 KB Output is correct
6 Correct 5 ms 27280 KB Output is correct
7 Correct 5 ms 27228 KB Output is correct
8 Correct 5 ms 27484 KB Output is correct
9 Correct 6 ms 27228 KB Output is correct
10 Correct 6 ms 27284 KB Output is correct
11 Correct 6 ms 27288 KB Output is correct
12 Correct 6 ms 27228 KB Output is correct
13 Correct 6 ms 27484 KB Output is correct
14 Correct 6 ms 27480 KB Output is correct
15 Correct 6 ms 27484 KB Output is correct
16 Correct 6 ms 27480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 409 ms 50008 KB Output is correct
2 Correct 370 ms 56808 KB Output is correct
3 Correct 381 ms 56676 KB Output is correct
4 Correct 397 ms 56628 KB Output is correct
5 Correct 389 ms 56652 KB Output is correct
6 Correct 373 ms 57224 KB Output is correct
7 Correct 369 ms 56912 KB Output is correct
8 Correct 384 ms 57228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 392 ms 50552 KB Output is correct
2 Correct 409 ms 57188 KB Output is correct
3 Correct 366 ms 56588 KB Output is correct
4 Correct 377 ms 57276 KB Output is correct
5 Correct 372 ms 56752 KB Output is correct
6 Correct 387 ms 56748 KB Output is correct
7 Correct 371 ms 56724 KB Output is correct
8 Correct 385 ms 57060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1617 ms 58268 KB Output is correct
2 Correct 631 ms 47964 KB Output is correct
3 Correct 966 ms 55600 KB Output is correct
4 Correct 918 ms 55536 KB Output is correct
5 Correct 908 ms 55548 KB Output is correct
6 Correct 940 ms 55888 KB Output is correct
7 Correct 983 ms 55732 KB Output is correct
8 Correct 897 ms 55792 KB Output is correct
9 Correct 929 ms 55608 KB Output is correct
10 Correct 918 ms 56148 KB Output is correct
11 Correct 928 ms 55632 KB Output is correct
12 Correct 1642 ms 58700 KB Output is correct
13 Correct 944 ms 55888 KB Output is correct
14 Correct 341 ms 65112 KB Output is correct
15 Correct 358 ms 65112 KB Output is correct
16 Correct 1547 ms 58924 KB Output is correct
17 Correct 1521 ms 58228 KB Output is correct
18 Correct 1536 ms 58600 KB Output is correct
19 Correct 622 ms 47956 KB Output is correct
20 Correct 628 ms 47952 KB Output is correct
21 Correct 626 ms 47956 KB Output is correct
22 Correct 624 ms 48212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1617 ms 58268 KB Output is correct
2 Correct 631 ms 47964 KB Output is correct
3 Correct 966 ms 55600 KB Output is correct
4 Correct 918 ms 55536 KB Output is correct
5 Correct 908 ms 55548 KB Output is correct
6 Correct 940 ms 55888 KB Output is correct
7 Correct 983 ms 55732 KB Output is correct
8 Correct 897 ms 55792 KB Output is correct
9 Correct 929 ms 55608 KB Output is correct
10 Correct 918 ms 56148 KB Output is correct
11 Correct 928 ms 55632 KB Output is correct
12 Correct 1642 ms 58700 KB Output is correct
13 Correct 944 ms 55888 KB Output is correct
14 Correct 341 ms 65112 KB Output is correct
15 Correct 358 ms 65112 KB Output is correct
16 Correct 1547 ms 58924 KB Output is correct
17 Correct 1521 ms 58228 KB Output is correct
18 Correct 1536 ms 58600 KB Output is correct
19 Correct 622 ms 47956 KB Output is correct
20 Correct 628 ms 47952 KB Output is correct
21 Correct 626 ms 47956 KB Output is correct
22 Correct 624 ms 48212 KB Output is correct
23 Correct 1532 ms 58856 KB Output is correct
24 Correct 638 ms 52484 KB Output is correct
25 Correct 904 ms 59520 KB Output is correct
26 Correct 840 ms 59588 KB Output is correct
27 Correct 856 ms 59620 KB Output is correct
28 Correct 843 ms 59856 KB Output is correct
29 Correct 840 ms 59780 KB Output is correct
30 Correct 855 ms 60140 KB Output is correct
31 Correct 856 ms 59736 KB Output is correct
32 Correct 861 ms 59804 KB Output is correct
33 Correct 862 ms 60080 KB Output is correct
34 Correct 1487 ms 63060 KB Output is correct
35 Correct 886 ms 59956 KB Output is correct
36 Correct 308 ms 63356 KB Output is correct
37 Correct 332 ms 64556 KB Output is correct
38 Correct 1533 ms 62928 KB Output is correct
39 Correct 1468 ms 62612 KB Output is correct
40 Correct 1520 ms 63448 KB Output is correct
41 Correct 648 ms 52308 KB Output is correct
42 Correct 634 ms 52480 KB Output is correct
43 Correct 667 ms 52456 KB Output is correct
44 Correct 662 ms 52560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 27224 KB Output is correct
2 Correct 5 ms 27224 KB Output is correct
3 Correct 5 ms 27228 KB Output is correct
4 Correct 5 ms 27056 KB Output is correct
5 Correct 5 ms 27228 KB Output is correct
6 Correct 5 ms 27280 KB Output is correct
7 Correct 5 ms 27228 KB Output is correct
8 Correct 5 ms 27484 KB Output is correct
9 Correct 6 ms 27228 KB Output is correct
10 Correct 6 ms 27284 KB Output is correct
11 Correct 6 ms 27288 KB Output is correct
12 Correct 6 ms 27228 KB Output is correct
13 Correct 6 ms 27484 KB Output is correct
14 Correct 6 ms 27480 KB Output is correct
15 Correct 6 ms 27484 KB Output is correct
16 Correct 6 ms 27480 KB Output is correct
17 Correct 409 ms 50008 KB Output is correct
18 Correct 370 ms 56808 KB Output is correct
19 Correct 381 ms 56676 KB Output is correct
20 Correct 397 ms 56628 KB Output is correct
21 Correct 389 ms 56652 KB Output is correct
22 Correct 373 ms 57224 KB Output is correct
23 Correct 369 ms 56912 KB Output is correct
24 Correct 384 ms 57228 KB Output is correct
25 Correct 392 ms 50552 KB Output is correct
26 Correct 409 ms 57188 KB Output is correct
27 Correct 366 ms 56588 KB Output is correct
28 Correct 377 ms 57276 KB Output is correct
29 Correct 372 ms 56752 KB Output is correct
30 Correct 387 ms 56748 KB Output is correct
31 Correct 371 ms 56724 KB Output is correct
32 Correct 385 ms 57060 KB Output is correct
33 Correct 1617 ms 58268 KB Output is correct
34 Correct 631 ms 47964 KB Output is correct
35 Correct 966 ms 55600 KB Output is correct
36 Correct 918 ms 55536 KB Output is correct
37 Correct 908 ms 55548 KB Output is correct
38 Correct 940 ms 55888 KB Output is correct
39 Correct 983 ms 55732 KB Output is correct
40 Correct 897 ms 55792 KB Output is correct
41 Correct 929 ms 55608 KB Output is correct
42 Correct 918 ms 56148 KB Output is correct
43 Correct 928 ms 55632 KB Output is correct
44 Correct 1642 ms 58700 KB Output is correct
45 Correct 944 ms 55888 KB Output is correct
46 Correct 341 ms 65112 KB Output is correct
47 Correct 358 ms 65112 KB Output is correct
48 Correct 1547 ms 58924 KB Output is correct
49 Correct 1521 ms 58228 KB Output is correct
50 Correct 1536 ms 58600 KB Output is correct
51 Correct 622 ms 47956 KB Output is correct
52 Correct 628 ms 47952 KB Output is correct
53 Correct 626 ms 47956 KB Output is correct
54 Correct 624 ms 48212 KB Output is correct
55 Correct 1532 ms 58856 KB Output is correct
56 Correct 638 ms 52484 KB Output is correct
57 Correct 904 ms 59520 KB Output is correct
58 Correct 840 ms 59588 KB Output is correct
59 Correct 856 ms 59620 KB Output is correct
60 Correct 843 ms 59856 KB Output is correct
61 Correct 840 ms 59780 KB Output is correct
62 Correct 855 ms 60140 KB Output is correct
63 Correct 856 ms 59736 KB Output is correct
64 Correct 861 ms 59804 KB Output is correct
65 Correct 862 ms 60080 KB Output is correct
66 Correct 1487 ms 63060 KB Output is correct
67 Correct 886 ms 59956 KB Output is correct
68 Correct 308 ms 63356 KB Output is correct
69 Correct 332 ms 64556 KB Output is correct
70 Correct 1533 ms 62928 KB Output is correct
71 Correct 1468 ms 62612 KB Output is correct
72 Correct 1520 ms 63448 KB Output is correct
73 Correct 648 ms 52308 KB Output is correct
74 Correct 634 ms 52480 KB Output is correct
75 Correct 667 ms 52456 KB Output is correct
76 Correct 662 ms 52560 KB Output is correct
77 Correct 353 ms 56764 KB Output is correct
78 Correct 372 ms 54552 KB Output is correct
79 Correct 270 ms 62052 KB Output is correct
80 Correct 293 ms 61916 KB Output is correct
81 Correct 281 ms 61776 KB Output is correct
82 Correct 288 ms 61848 KB Output is correct
83 Correct 257 ms 62176 KB Output is correct
84 Correct 276 ms 62252 KB Output is correct
85 Correct 273 ms 62072 KB Output is correct
86 Correct 277 ms 61900 KB Output is correct
87 Correct 276 ms 62288 KB Output is correct
88 Correct 330 ms 56300 KB Output is correct
89 Correct 273 ms 62288 KB Output is correct
90 Correct 341 ms 63856 KB Output is correct
91 Correct 353 ms 65384 KB Output is correct
92 Correct 338 ms 56544 KB Output is correct
93 Correct 312 ms 56472 KB Output is correct
94 Correct 312 ms 56168 KB Output is correct
95 Correct 360 ms 54584 KB Output is correct
96 Correct 368 ms 54564 KB Output is correct
97 Correct 364 ms 54612 KB Output is correct
98 Correct 410 ms 54588 KB Output is correct