Submission #317765

# Submission time Handle Problem Language Result Execution time Memory
317765 2020-10-30T10:42:13 Z parsabahrami Aesthetic (NOI20_aesthetic) C++17
100 / 100
1054 ms 85752 KB
//! The Leader Of Retards Bemola
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
 
using namespace std;

typedef int ll;
typedef pair<ll, ll> pll;
 
#define sz(x)                       (ll) x.size()
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second

ll Pow(ll a, ll b, ll md, ll ans = 1) {
    for (; b; b >>= 1, a = a * a % md)
        if (b & 1)
            ans = ans * a % md;
    return ans % md;
}
const ll MAXN = 3e5 + 10;
const long long int INF = 1e18;
const ll MOD  = 1e9 + 7;
ll chk[2][MAXN], L[MAXN], mn[MAXN], mark[MAXN], n, m, s, t, timer, f = 0; long long int ans = 0, dist[2][MAXN], W[MAXN], mx[MAXN];
vector<pair<long long int, ll>> adj[2][MAXN]; pll E[MAXN];
 
void Dijkstra(ll St, ll ind) {
    priority_queue<pair<long long int, ll>> pq;
    pq.push({0, St});
    dist[ind][St] = 0;
    while (sz(pq)) {
        ll v = pq.top().S;
        pq.pop();
        if (mark[v]) continue;
        mark[v] = 1;
        for (pll nei: adj[0][v]) {
            ll u = nei.F, w = nei.S;
            if (mark[u]) continue;
            if (dist[ind][u] > dist[ind][v] + w) {
                dist[ind][u] = dist[ind][v] + w;
                pq.push({-dist[ind][u], u});
            }
        }
    }
    return;
}
 
void DFS(ll v, long long int x, ll p = -1) {
    assert(L[v] == 0 && mn[v] == MOD);
    mn[v] = L[v] = timer++;
    mark[v] = 1;
    for (pll nei : adj[1][v]) {
        ll u = nei.F, id = nei.S;
        if (chk[0][id] == 0) continue;
        if (mark[u] == 0) {
            DFS(u, x, v);
            if (mn[u] > L[v] && L[n] >= L[u] && chk[1][id]) f = 1;
            else  mn[v] = min(mn[v], mn[u]);
        } else if (u != p) {
            mn[v] = min(mn[v], L[u]);
        }
    }
}

ll check(long long int x) {
    for (ll i = 1; i <= m; i++) {
        ll u = E[i].F, v = E[i].S;
        chk[0][i] = bool(min(dist[0][u] + W[i] + dist[1][v], dist[0][v] + W[i] + dist[1][u]) <= x);
        chk[1][i] = bool(min(dist[0][u] + W[i] + dist[1][v], dist[0][v] + W[i] + dist[1][u]) + mx[i + 1] > x);
    }
    fill(mn + 1, mn + n + 1, MOD);
    fill(L + 1, L + n + 1, 0);
    memset(mark, 0, sizeof mark);
    timer = 1; f = 0;
    DFS(s, x);
    if (f || L[n] == 0) return 1;
    return 0;
}

int main() {
    fill(dist[0], dist[0] + MAXN, INF);
    fill(dist[1], dist[1] + MAXN, INF);
    scanf("%d%d", &n, &m);
    for (ll i = 1; i <= m; i++) {
        ll u, v; long long int w;
        scanf("%d%d%lld", &u, &v, &w);
        adj[0][u].push_back({v, w});
        adj[0][v].push_back({u, w});
        adj[1][u].push_back({v, i});
        adj[1][v].push_back({u, i});
        W[i] = w;
        E[i] = {u, v};
    }
    for (ll i = m; i >= 1; i--) {
        mx[i] = max(mx[i + 1], W[i]);
    }
    s = 1, t = n;
    Dijkstra(s, 0);
    memset(mark, 0, sizeof mark);
    Dijkstra(t, 1);
    long long int l = dist[0][t], r = dist[0][t] + mx[1] + 1;
    while (r - l > 1) {
        long long int mid = (l + r) / 2;
        if (check(mid)) l = mid;
        else r = mid;
    }
    //printf("%d\n", check(9));
    if (check(l)) l++;
    printf("%lld\n", l);
    return 0;
}

Compilation message

Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:84:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   84 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
Aesthetic.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   87 |         scanf("%d%d%lld", &u, &v, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 20352 KB Output is correct
2 Correct 18 ms 20352 KB Output is correct
3 Correct 15 ms 20352 KB Output is correct
4 Correct 15 ms 20352 KB Output is correct
5 Correct 16 ms 20352 KB Output is correct
6 Correct 16 ms 20352 KB Output is correct
7 Correct 15 ms 20352 KB Output is correct
8 Correct 15 ms 20480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 20352 KB Output is correct
2 Correct 18 ms 20352 KB Output is correct
3 Correct 15 ms 20352 KB Output is correct
4 Correct 15 ms 20352 KB Output is correct
5 Correct 16 ms 20352 KB Output is correct
6 Correct 16 ms 20352 KB Output is correct
7 Correct 15 ms 20352 KB Output is correct
8 Correct 15 ms 20480 KB Output is correct
9 Correct 18 ms 20736 KB Output is correct
10 Correct 18 ms 20608 KB Output is correct
11 Correct 18 ms 20608 KB Output is correct
12 Correct 18 ms 20608 KB Output is correct
13 Correct 18 ms 20608 KB Output is correct
14 Correct 17 ms 20736 KB Output is correct
15 Correct 18 ms 20736 KB Output is correct
16 Correct 18 ms 20736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 920 ms 70648 KB Output is correct
2 Correct 961 ms 71028 KB Output is correct
3 Correct 909 ms 70264 KB Output is correct
4 Correct 914 ms 70392 KB Output is correct
5 Correct 973 ms 70520 KB Output is correct
6 Correct 971 ms 71544 KB Output is correct
7 Correct 945 ms 71360 KB Output is correct
8 Correct 965 ms 71800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 970 ms 71604 KB Output is correct
2 Correct 939 ms 71032 KB Output is correct
3 Correct 944 ms 70892 KB Output is correct
4 Correct 1054 ms 71752 KB Output is correct
5 Correct 926 ms 70728 KB Output is correct
6 Correct 936 ms 70940 KB Output is correct
7 Correct 969 ms 70776 KB Output is correct
8 Correct 997 ms 71160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 707 ms 66908 KB Output is correct
2 Correct 307 ms 63992 KB Output is correct
3 Correct 464 ms 72184 KB Output is correct
4 Correct 479 ms 72312 KB Output is correct
5 Correct 469 ms 72312 KB Output is correct
6 Correct 453 ms 72552 KB Output is correct
7 Correct 456 ms 72312 KB Output is correct
8 Correct 474 ms 72568 KB Output is correct
9 Correct 467 ms 72312 KB Output is correct
10 Correct 472 ms 72824 KB Output is correct
11 Correct 487 ms 72824 KB Output is correct
12 Correct 737 ms 67448 KB Output is correct
13 Correct 472 ms 72440 KB Output is correct
14 Correct 256 ms 85752 KB Output is correct
15 Correct 249 ms 85752 KB Output is correct
16 Correct 715 ms 67808 KB Output is correct
17 Correct 685 ms 66420 KB Output is correct
18 Correct 716 ms 67296 KB Output is correct
19 Correct 314 ms 63992 KB Output is correct
20 Correct 316 ms 64120 KB Output is correct
21 Correct 318 ms 64012 KB Output is correct
22 Correct 308 ms 64120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 707 ms 66908 KB Output is correct
2 Correct 307 ms 63992 KB Output is correct
3 Correct 464 ms 72184 KB Output is correct
4 Correct 479 ms 72312 KB Output is correct
5 Correct 469 ms 72312 KB Output is correct
6 Correct 453 ms 72552 KB Output is correct
7 Correct 456 ms 72312 KB Output is correct
8 Correct 474 ms 72568 KB Output is correct
9 Correct 467 ms 72312 KB Output is correct
10 Correct 472 ms 72824 KB Output is correct
11 Correct 487 ms 72824 KB Output is correct
12 Correct 737 ms 67448 KB Output is correct
13 Correct 472 ms 72440 KB Output is correct
14 Correct 256 ms 85752 KB Output is correct
15 Correct 249 ms 85752 KB Output is correct
16 Correct 715 ms 67808 KB Output is correct
17 Correct 685 ms 66420 KB Output is correct
18 Correct 716 ms 67296 KB Output is correct
19 Correct 314 ms 63992 KB Output is correct
20 Correct 316 ms 64120 KB Output is correct
21 Correct 318 ms 64012 KB Output is correct
22 Correct 308 ms 64120 KB Output is correct
23 Correct 793 ms 67964 KB Output is correct
24 Correct 382 ms 64248 KB Output is correct
25 Correct 432 ms 67612 KB Output is correct
26 Correct 439 ms 66940 KB Output is correct
27 Correct 439 ms 66936 KB Output is correct
28 Correct 450 ms 68216 KB Output is correct
29 Correct 451 ms 66936 KB Output is correct
30 Correct 454 ms 67320 KB Output is correct
31 Correct 457 ms 67704 KB Output is correct
32 Correct 454 ms 66936 KB Output is correct
33 Correct 450 ms 67964 KB Output is correct
34 Correct 804 ms 67620 KB Output is correct
35 Correct 449 ms 67576 KB Output is correct
36 Correct 267 ms 77116 KB Output is correct
37 Correct 258 ms 77912 KB Output is correct
38 Correct 751 ms 67212 KB Output is correct
39 Correct 784 ms 67000 KB Output is correct
40 Correct 820 ms 67744 KB Output is correct
41 Correct 379 ms 64120 KB Output is correct
42 Correct 383 ms 64120 KB Output is correct
43 Correct 377 ms 64120 KB Output is correct
44 Correct 372 ms 64120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 20352 KB Output is correct
2 Correct 18 ms 20352 KB Output is correct
3 Correct 15 ms 20352 KB Output is correct
4 Correct 15 ms 20352 KB Output is correct
5 Correct 16 ms 20352 KB Output is correct
6 Correct 16 ms 20352 KB Output is correct
7 Correct 15 ms 20352 KB Output is correct
8 Correct 15 ms 20480 KB Output is correct
9 Correct 18 ms 20736 KB Output is correct
10 Correct 18 ms 20608 KB Output is correct
11 Correct 18 ms 20608 KB Output is correct
12 Correct 18 ms 20608 KB Output is correct
13 Correct 18 ms 20608 KB Output is correct
14 Correct 17 ms 20736 KB Output is correct
15 Correct 18 ms 20736 KB Output is correct
16 Correct 18 ms 20736 KB Output is correct
17 Correct 920 ms 70648 KB Output is correct
18 Correct 961 ms 71028 KB Output is correct
19 Correct 909 ms 70264 KB Output is correct
20 Correct 914 ms 70392 KB Output is correct
21 Correct 973 ms 70520 KB Output is correct
22 Correct 971 ms 71544 KB Output is correct
23 Correct 945 ms 71360 KB Output is correct
24 Correct 965 ms 71800 KB Output is correct
25 Correct 970 ms 71604 KB Output is correct
26 Correct 939 ms 71032 KB Output is correct
27 Correct 944 ms 70892 KB Output is correct
28 Correct 1054 ms 71752 KB Output is correct
29 Correct 926 ms 70728 KB Output is correct
30 Correct 936 ms 70940 KB Output is correct
31 Correct 969 ms 70776 KB Output is correct
32 Correct 997 ms 71160 KB Output is correct
33 Correct 707 ms 66908 KB Output is correct
34 Correct 307 ms 63992 KB Output is correct
35 Correct 464 ms 72184 KB Output is correct
36 Correct 479 ms 72312 KB Output is correct
37 Correct 469 ms 72312 KB Output is correct
38 Correct 453 ms 72552 KB Output is correct
39 Correct 456 ms 72312 KB Output is correct
40 Correct 474 ms 72568 KB Output is correct
41 Correct 467 ms 72312 KB Output is correct
42 Correct 472 ms 72824 KB Output is correct
43 Correct 487 ms 72824 KB Output is correct
44 Correct 737 ms 67448 KB Output is correct
45 Correct 472 ms 72440 KB Output is correct
46 Correct 256 ms 85752 KB Output is correct
47 Correct 249 ms 85752 KB Output is correct
48 Correct 715 ms 67808 KB Output is correct
49 Correct 685 ms 66420 KB Output is correct
50 Correct 716 ms 67296 KB Output is correct
51 Correct 314 ms 63992 KB Output is correct
52 Correct 316 ms 64120 KB Output is correct
53 Correct 318 ms 64012 KB Output is correct
54 Correct 308 ms 64120 KB Output is correct
55 Correct 793 ms 67964 KB Output is correct
56 Correct 382 ms 64248 KB Output is correct
57 Correct 432 ms 67612 KB Output is correct
58 Correct 439 ms 66940 KB Output is correct
59 Correct 439 ms 66936 KB Output is correct
60 Correct 450 ms 68216 KB Output is correct
61 Correct 451 ms 66936 KB Output is correct
62 Correct 454 ms 67320 KB Output is correct
63 Correct 457 ms 67704 KB Output is correct
64 Correct 454 ms 66936 KB Output is correct
65 Correct 450 ms 67964 KB Output is correct
66 Correct 804 ms 67620 KB Output is correct
67 Correct 449 ms 67576 KB Output is correct
68 Correct 267 ms 77116 KB Output is correct
69 Correct 258 ms 77912 KB Output is correct
70 Correct 751 ms 67212 KB Output is correct
71 Correct 784 ms 67000 KB Output is correct
72 Correct 820 ms 67744 KB Output is correct
73 Correct 379 ms 64120 KB Output is correct
74 Correct 383 ms 64120 KB Output is correct
75 Correct 377 ms 64120 KB Output is correct
76 Correct 372 ms 64120 KB Output is correct
77 Correct 1006 ms 70496 KB Output is correct
78 Correct 614 ms 66424 KB Output is correct
79 Correct 639 ms 74744 KB Output is correct
80 Correct 640 ms 74740 KB Output is correct
81 Correct 623 ms 74872 KB Output is correct
82 Correct 612 ms 74336 KB Output is correct
83 Correct 618 ms 75000 KB Output is correct
84 Correct 638 ms 75236 KB Output is correct
85 Correct 613 ms 74616 KB Output is correct
86 Correct 625 ms 74804 KB Output is correct
87 Correct 669 ms 75128 KB Output is correct
88 Correct 913 ms 69792 KB Output is correct
89 Correct 630 ms 75128 KB Output is correct
90 Correct 411 ms 77624 KB Output is correct
91 Correct 426 ms 78292 KB Output is correct
92 Correct 962 ms 70192 KB Output is correct
93 Correct 921 ms 69668 KB Output is correct
94 Correct 866 ms 68888 KB Output is correct
95 Correct 655 ms 66504 KB Output is correct
96 Correct 628 ms 66484 KB Output is correct
97 Correct 617 ms 66424 KB Output is correct
98 Correct 603 ms 66424 KB Output is correct