Submission #459650

# Submission time Handle Problem Language Result Execution time Memory
459650 2021-08-08T21:49:41 Z nickmet2004 Aesthetic (NOI20_aesthetic) C++11
100 / 100
918 ms 84944 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<pair<ll, pair<ll, ll > > > v[300009];
vector<ll> T[300009],W[300009];
ll d1[300009],dn[300009], f[300009], g[300009],ea[300009],eb[300009],ec[300009], par[300009],path[300009],wh[300009];
multiset<pair<ll,ll> > S;
void ad(ll x){
    g[x] = 1;
    for(auto E : v[x]){
        ll y = E.first, l = E.second.first,  u= E.second.second;
        auto it= S.find({dn[y] + l + d1[x], u});
        if(g[y] == 1) S.erase(it);
        if(g[y] == 0) S.insert({dn[x] + l + d1[y], u});
    }
}
void dfs(int x, int p){
    if(path[x]) wh[x] = x;
    else wh[x] = wh[p];
    T[wh[x]].push_back(x);
    for(int y : W[x]){
        dfs(y, x);
    }
}
ll A = 0;
main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, m;
    cin >> n >> m;
    for(ll i = 0; i < m; i++){
        cin>>ea[i]>>eb[i]>>ec[i];
    }
    for(ll i = m-1; i >= 0; i--){
        ll a = ea[i], b = eb[i], c = ec[i];
        if(a != b){
            v[a].push_back({b, {c,A}});
            v[b].push_back({a, {c,A}});
        }
        A = max(A, c);
    }
    for(ll i = 1; i <= n; i++){
        d1[i] = 1e18;
        dn[i] = 1e18;
    }
    d1[1] = 0;
    dn[n] = 0;
    priority_queue<pair<ll, ll> > q;
    q.push({0, 1});
    while(q.size()){
        ll x = q.top().second;
        q.pop();
        if(f[x]) continue;
        f[x] = 1;
        for(auto E: v[x]){
            ll y = E.first, l = E.second.first;
            if(!f[y] && d1[y] > d1[x] + l){
                d1[y] = d1[x] + l;
                par[y] = x;
                q.push({-d1[y], y});
            }
        }
    }
    q.push({0, n});
    for(ll i = 1; i <= n; i++)
        f[i] = 0;
    while(q.size()){
        ll x = q.top().second;
        q.pop();
        if(f[x]) continue;
        f[x] = 1;
        for(auto E: v[x]){
            ll y = E.first, l = E.second.first;
            if(!f[y] && dn[y] > dn[x] + l){
                dn[y] = dn[x] + l;
                q.push({-dn[y], y});
            }
        }
    }
    ll ans = d1[n];
    ll X = n;
    while(1){
        path[X] = 1;
        if(X == 1) break;
        X = par[X];
    }
 
    for(ll i = 1; i <= n; i++){
        W[par[i]].push_back(i);
    }
    dfs(1,0);
    ll x = n;
    while(1){
        for(ll y : T[x])
            ad(y);
        if(x == 1) break;
        x = par[x];
        if(S.size() == 0) continue;
        ll U = S.begin()->first + S.begin()->second;
        auto it = S.begin();
        it++;
        if(it != S.end()) U = min(U, it->first);
        ans = max(ans,   U);
    }
    cout<<ans<<endl;
}

Compilation message

Aesthetic.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 21452 KB Output is correct
2 Correct 14 ms 21480 KB Output is correct
3 Correct 13 ms 21452 KB Output is correct
4 Correct 13 ms 21480 KB Output is correct
5 Correct 13 ms 21476 KB Output is correct
6 Correct 13 ms 21504 KB Output is correct
7 Correct 14 ms 21436 KB Output is correct
8 Correct 13 ms 21452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 21452 KB Output is correct
2 Correct 14 ms 21480 KB Output is correct
3 Correct 13 ms 21452 KB Output is correct
4 Correct 13 ms 21480 KB Output is correct
5 Correct 13 ms 21476 KB Output is correct
6 Correct 13 ms 21504 KB Output is correct
7 Correct 14 ms 21436 KB Output is correct
8 Correct 13 ms 21452 KB Output is correct
9 Correct 15 ms 21784 KB Output is correct
10 Correct 15 ms 21836 KB Output is correct
11 Correct 14 ms 21708 KB Output is correct
12 Correct 14 ms 21756 KB Output is correct
13 Correct 15 ms 21788 KB Output is correct
14 Correct 15 ms 21804 KB Output is correct
15 Correct 15 ms 21784 KB Output is correct
16 Correct 15 ms 21792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 730 ms 72000 KB Output is correct
2 Correct 739 ms 72108 KB Output is correct
3 Correct 749 ms 71932 KB Output is correct
4 Correct 717 ms 72304 KB Output is correct
5 Correct 733 ms 72484 KB Output is correct
6 Correct 755 ms 73732 KB Output is correct
7 Correct 740 ms 73128 KB Output is correct
8 Correct 748 ms 73696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 745 ms 73896 KB Output is correct
2 Correct 764 ms 72948 KB Output is correct
3 Correct 752 ms 71064 KB Output is correct
4 Correct 772 ms 71624 KB Output is correct
5 Correct 752 ms 73008 KB Output is correct
6 Correct 752 ms 71816 KB Output is correct
7 Correct 752 ms 72072 KB Output is correct
8 Correct 737 ms 73228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 710 ms 66740 KB Output is correct
2 Correct 307 ms 70820 KB Output is correct
3 Correct 390 ms 62348 KB Output is correct
4 Correct 428 ms 62648 KB Output is correct
5 Correct 434 ms 62336 KB Output is correct
6 Correct 397 ms 62652 KB Output is correct
7 Correct 388 ms 62656 KB Output is correct
8 Correct 378 ms 62660 KB Output is correct
9 Correct 381 ms 62272 KB Output is correct
10 Correct 404 ms 62664 KB Output is correct
11 Correct 387 ms 62016 KB Output is correct
12 Correct 736 ms 67324 KB Output is correct
13 Correct 437 ms 62524 KB Output is correct
14 Correct 288 ms 82580 KB Output is correct
15 Correct 202 ms 72344 KB Output is correct
16 Correct 751 ms 67444 KB Output is correct
17 Correct 711 ms 66172 KB Output is correct
18 Correct 740 ms 66976 KB Output is correct
19 Correct 305 ms 71052 KB Output is correct
20 Correct 320 ms 71124 KB Output is correct
21 Correct 308 ms 71100 KB Output is correct
22 Correct 305 ms 70984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 710 ms 66740 KB Output is correct
2 Correct 307 ms 70820 KB Output is correct
3 Correct 390 ms 62348 KB Output is correct
4 Correct 428 ms 62648 KB Output is correct
5 Correct 434 ms 62336 KB Output is correct
6 Correct 397 ms 62652 KB Output is correct
7 Correct 388 ms 62656 KB Output is correct
8 Correct 378 ms 62660 KB Output is correct
9 Correct 381 ms 62272 KB Output is correct
10 Correct 404 ms 62664 KB Output is correct
11 Correct 387 ms 62016 KB Output is correct
12 Correct 736 ms 67324 KB Output is correct
13 Correct 437 ms 62524 KB Output is correct
14 Correct 288 ms 82580 KB Output is correct
15 Correct 202 ms 72344 KB Output is correct
16 Correct 751 ms 67444 KB Output is correct
17 Correct 711 ms 66172 KB Output is correct
18 Correct 740 ms 66976 KB Output is correct
19 Correct 305 ms 71052 KB Output is correct
20 Correct 320 ms 71124 KB Output is correct
21 Correct 308 ms 71100 KB Output is correct
22 Correct 305 ms 70984 KB Output is correct
23 Correct 828 ms 67704 KB Output is correct
24 Correct 375 ms 71200 KB Output is correct
25 Correct 502 ms 59996 KB Output is correct
26 Correct 494 ms 60348 KB Output is correct
27 Correct 445 ms 59972 KB Output is correct
28 Correct 493 ms 60764 KB Output is correct
29 Correct 472 ms 59476 KB Output is correct
30 Correct 493 ms 60460 KB Output is correct
31 Correct 457 ms 60616 KB Output is correct
32 Correct 438 ms 59176 KB Output is correct
33 Correct 465 ms 60120 KB Output is correct
34 Correct 794 ms 67564 KB Output is correct
35 Correct 434 ms 59300 KB Output is correct
36 Correct 286 ms 84792 KB Output is correct
37 Correct 302 ms 84828 KB Output is correct
38 Correct 762 ms 67132 KB Output is correct
39 Correct 768 ms 66816 KB Output is correct
40 Correct 850 ms 67752 KB Output is correct
41 Correct 367 ms 71124 KB Output is correct
42 Correct 369 ms 71144 KB Output is correct
43 Correct 363 ms 71200 KB Output is correct
44 Correct 367 ms 71152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 21452 KB Output is correct
2 Correct 14 ms 21480 KB Output is correct
3 Correct 13 ms 21452 KB Output is correct
4 Correct 13 ms 21480 KB Output is correct
5 Correct 13 ms 21476 KB Output is correct
6 Correct 13 ms 21504 KB Output is correct
7 Correct 14 ms 21436 KB Output is correct
8 Correct 13 ms 21452 KB Output is correct
9 Correct 15 ms 21784 KB Output is correct
10 Correct 15 ms 21836 KB Output is correct
11 Correct 14 ms 21708 KB Output is correct
12 Correct 14 ms 21756 KB Output is correct
13 Correct 15 ms 21788 KB Output is correct
14 Correct 15 ms 21804 KB Output is correct
15 Correct 15 ms 21784 KB Output is correct
16 Correct 15 ms 21792 KB Output is correct
17 Correct 730 ms 72000 KB Output is correct
18 Correct 739 ms 72108 KB Output is correct
19 Correct 749 ms 71932 KB Output is correct
20 Correct 717 ms 72304 KB Output is correct
21 Correct 733 ms 72484 KB Output is correct
22 Correct 755 ms 73732 KB Output is correct
23 Correct 740 ms 73128 KB Output is correct
24 Correct 748 ms 73696 KB Output is correct
25 Correct 745 ms 73896 KB Output is correct
26 Correct 764 ms 72948 KB Output is correct
27 Correct 752 ms 71064 KB Output is correct
28 Correct 772 ms 71624 KB Output is correct
29 Correct 752 ms 73008 KB Output is correct
30 Correct 752 ms 71816 KB Output is correct
31 Correct 752 ms 72072 KB Output is correct
32 Correct 737 ms 73228 KB Output is correct
33 Correct 710 ms 66740 KB Output is correct
34 Correct 307 ms 70820 KB Output is correct
35 Correct 390 ms 62348 KB Output is correct
36 Correct 428 ms 62648 KB Output is correct
37 Correct 434 ms 62336 KB Output is correct
38 Correct 397 ms 62652 KB Output is correct
39 Correct 388 ms 62656 KB Output is correct
40 Correct 378 ms 62660 KB Output is correct
41 Correct 381 ms 62272 KB Output is correct
42 Correct 404 ms 62664 KB Output is correct
43 Correct 387 ms 62016 KB Output is correct
44 Correct 736 ms 67324 KB Output is correct
45 Correct 437 ms 62524 KB Output is correct
46 Correct 288 ms 82580 KB Output is correct
47 Correct 202 ms 72344 KB Output is correct
48 Correct 751 ms 67444 KB Output is correct
49 Correct 711 ms 66172 KB Output is correct
50 Correct 740 ms 66976 KB Output is correct
51 Correct 305 ms 71052 KB Output is correct
52 Correct 320 ms 71124 KB Output is correct
53 Correct 308 ms 71100 KB Output is correct
54 Correct 305 ms 70984 KB Output is correct
55 Correct 828 ms 67704 KB Output is correct
56 Correct 375 ms 71200 KB Output is correct
57 Correct 502 ms 59996 KB Output is correct
58 Correct 494 ms 60348 KB Output is correct
59 Correct 445 ms 59972 KB Output is correct
60 Correct 493 ms 60764 KB Output is correct
61 Correct 472 ms 59476 KB Output is correct
62 Correct 493 ms 60460 KB Output is correct
63 Correct 457 ms 60616 KB Output is correct
64 Correct 438 ms 59176 KB Output is correct
65 Correct 465 ms 60120 KB Output is correct
66 Correct 794 ms 67564 KB Output is correct
67 Correct 434 ms 59300 KB Output is correct
68 Correct 286 ms 84792 KB Output is correct
69 Correct 302 ms 84828 KB Output is correct
70 Correct 762 ms 67132 KB Output is correct
71 Correct 768 ms 66816 KB Output is correct
72 Correct 850 ms 67752 KB Output is correct
73 Correct 367 ms 71124 KB Output is correct
74 Correct 369 ms 71144 KB Output is correct
75 Correct 363 ms 71200 KB Output is correct
76 Correct 367 ms 71152 KB Output is correct
77 Correct 862 ms 68336 KB Output is correct
78 Correct 378 ms 71212 KB Output is correct
79 Correct 516 ms 60104 KB Output is correct
80 Correct 481 ms 58736 KB Output is correct
81 Correct 550 ms 60360 KB Output is correct
82 Correct 517 ms 59740 KB Output is correct
83 Correct 542 ms 58976 KB Output is correct
84 Correct 563 ms 59236 KB Output is correct
85 Correct 540 ms 61016 KB Output is correct
86 Correct 576 ms 59892 KB Output is correct
87 Correct 553 ms 59412 KB Output is correct
88 Correct 822 ms 67404 KB Output is correct
89 Correct 506 ms 60272 KB Output is correct
90 Correct 303 ms 84900 KB Output is correct
91 Correct 353 ms 84944 KB Output is correct
92 Correct 868 ms 68076 KB Output is correct
93 Correct 918 ms 73808 KB Output is correct
94 Correct 887 ms 73252 KB Output is correct
95 Correct 374 ms 78020 KB Output is correct
96 Correct 380 ms 77940 KB Output is correct
97 Correct 378 ms 77836 KB Output is correct
98 Correct 390 ms 78036 KB Output is correct