Submission #459634

# Submission time Handle Problem Language Result Execution time Memory
459634 2021-08-08T21:05:48 Z nickmet2004 Aesthetic (NOI20_aesthetic) C++11
73 / 100
899 ms 134560 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 300005;
ll n , m , au[300005] , av[300005] , aw[300005];
ll u , v , w , A;
vector<pair<ll, pair<ll , ll> > >  adj[300005];
ll d1[300005] , dn[300005] , f[300005] , par[300005] , path[300005] , son[300005];
multiset<pair<ll , ll>> S;
vector<ll> B[N] , T[N];
void q(ll x){
    f[x] = 1;
    for(auto y : adj[x]){
        //cout << "h";
        auto it = S.find({dn[y.first] + y.second.first + d1[x] , y.second.second});
        if(f[y.first]) S.erase(it);
        else S.insert({dn[x] + y.second.first + d1[y.first] , y.second.second});
    }
}
void dfs(int u , int p){
    if(path[u]) son[u] = u;
    else son[u] = son[p];
    T[son[u]].emplace_back(u);
    for(int v : B[u]) dfs(v , u);
}
main (){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i  =0; i <m; ++i) cin >> au[i] >> av[i] >> aw[i];
    for(int i = m - 1; ~i; --i){
        u = au[i] , v = av[i] , w= aw[i];
        adj[u].push_back({v , {w , A}});
        adj[v].push_back({u , {w , A}});
        A = max(A , w);
        //cout << "j";
    }

    for(int i = 1; i <= n; ++i) d1[i] = dn[i] = 1e18;
    d1[1] = 0;
    dn[n] = 0;
    priority_queue<pair<ll , ll> > pq;
    pq.push({0 , 1});
    while(pq.size()){
        auto T = pq.top(); pq.pop();
        u = T.second , w = -T.first;
        if(f[u])continue;
        f[u] = 1;
        for(auto e : adj[u]){
            v = e.first;
            if(!f[v] && d1[v] > w + e.second.first){
                par[v] = u;
                d1[v] = w + e.second.first;
                pq.push({-d1[v] , v});
            }
        }
        //cout << "k";
    }
    for(int i = 1; i <= n; ++i)f[i] = 0;
    //memset(f , 0 ,sizeof(f));
    pq.push({0, n});
    while(pq.size()){
        auto T = pq.top(); pq.pop();
        u = T.second , w = -T.first;
        if(f[u])continue;
        f[u] = 1;
        for(auto e : adj[u]){
            v = e.first;
            if(!f[v] && dn[v] > w + e.second.first){
                dn[v]= w + e.second.first;
                pq.push({-dn[v] , v});
            }
        }
        //cout << "l";
    }

    ll X = n;
    while(1){
        path[X] = 1;
        if(X == 1) break;
        X = par[X];
        //cout << "n";
    }

    for(int i = 1; i <= n; ++i)B[par[i]].emplace_back(i);
    dfs(1 , 0);

    for(int i = 1; i <= n; ++i) f[i] =0;
    ll s = n;
    ll ans = d1[n];
    //cout << "ka";
    ll k;
    while(1){
        //cout << "ha";
        if(s == 1)break;
        for(ll v : T[s]) q(v);
        s = par[s];
        k = S.begin()->first + S.begin()->second;
        auto i = S.begin();
        ++i;
        if(i != S.end()) k =min(k , i->first);
        ans = max(ans , k);
    }
    cout << ans;
}

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 12 ms 21516 KB Output is correct
2 Correct 12 ms 21492 KB Output is correct
3 Correct 12 ms 21464 KB Output is correct
4 Correct 15 ms 21452 KB Output is correct
5 Correct 12 ms 21492 KB Output is correct
6 Correct 15 ms 21452 KB Output is correct
7 Correct 13 ms 21484 KB Output is correct
8 Correct 12 ms 21448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21516 KB Output is correct
2 Correct 12 ms 21492 KB Output is correct
3 Correct 12 ms 21464 KB Output is correct
4 Correct 15 ms 21452 KB Output is correct
5 Correct 12 ms 21492 KB Output is correct
6 Correct 15 ms 21452 KB Output is correct
7 Correct 13 ms 21484 KB Output is correct
8 Correct 12 ms 21448 KB Output is correct
9 Correct 14 ms 21864 KB Output is correct
10 Correct 14 ms 21864 KB Output is correct
11 Correct 14 ms 21800 KB Output is correct
12 Correct 14 ms 21772 KB Output is correct
13 Correct 13 ms 21720 KB Output is correct
14 Correct 14 ms 21800 KB Output is correct
15 Correct 14 ms 21800 KB Output is correct
16 Correct 14 ms 21836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 737 ms 70512 KB Output is correct
2 Correct 731 ms 69948 KB Output is correct
3 Correct 710 ms 70124 KB Output is correct
4 Correct 720 ms 70300 KB Output is correct
5 Correct 686 ms 70500 KB Output is correct
6 Correct 712 ms 71912 KB Output is correct
7 Correct 716 ms 71096 KB Output is correct
8 Correct 774 ms 71852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 725 ms 72048 KB Output is correct
2 Correct 803 ms 70852 KB Output is correct
3 Correct 785 ms 69260 KB Output is correct
4 Correct 811 ms 71440 KB Output is correct
5 Correct 742 ms 71060 KB Output is correct
6 Correct 757 ms 71848 KB Output is correct
7 Correct 706 ms 71052 KB Output is correct
8 Correct 713 ms 71236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 581 ms 65280 KB Output is correct
2 Correct 319 ms 69024 KB Output is correct
3 Correct 290 ms 60160 KB Output is correct
4 Correct 293 ms 58984 KB Output is correct
5 Correct 266 ms 58632 KB Output is correct
6 Correct 273 ms 59888 KB Output is correct
7 Correct 281 ms 58288 KB Output is correct
8 Correct 269 ms 58892 KB Output is correct
9 Correct 278 ms 57740 KB Output is correct
10 Correct 292 ms 60980 KB Output is correct
11 Correct 282 ms 58460 KB Output is correct
12 Correct 636 ms 65900 KB Output is correct
13 Correct 261 ms 58684 KB Output is correct
14 Correct 253 ms 81100 KB Output is correct
15 Correct 188 ms 71140 KB Output is correct
16 Correct 548 ms 64948 KB Output is correct
17 Correct 598 ms 65008 KB Output is correct
18 Correct 463 ms 63304 KB Output is correct
19 Correct 303 ms 69344 KB Output is correct
20 Correct 307 ms 69412 KB Output is correct
21 Correct 299 ms 69312 KB Output is correct
22 Correct 300 ms 69172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 581 ms 65280 KB Output is correct
2 Correct 319 ms 69024 KB Output is correct
3 Correct 290 ms 60160 KB Output is correct
4 Correct 293 ms 58984 KB Output is correct
5 Correct 266 ms 58632 KB Output is correct
6 Correct 273 ms 59888 KB Output is correct
7 Correct 281 ms 58288 KB Output is correct
8 Correct 269 ms 58892 KB Output is correct
9 Correct 278 ms 57740 KB Output is correct
10 Correct 292 ms 60980 KB Output is correct
11 Correct 282 ms 58460 KB Output is correct
12 Correct 636 ms 65900 KB Output is correct
13 Correct 261 ms 58684 KB Output is correct
14 Correct 253 ms 81100 KB Output is correct
15 Correct 188 ms 71140 KB Output is correct
16 Correct 548 ms 64948 KB Output is correct
17 Correct 598 ms 65008 KB Output is correct
18 Correct 463 ms 63304 KB Output is correct
19 Correct 303 ms 69344 KB Output is correct
20 Correct 307 ms 69412 KB Output is correct
21 Correct 299 ms 69312 KB Output is correct
22 Correct 300 ms 69172 KB Output is correct
23 Correct 711 ms 66360 KB Output is correct
24 Correct 361 ms 69448 KB Output is correct
25 Correct 408 ms 59172 KB Output is correct
26 Correct 382 ms 58872 KB Output is correct
27 Correct 369 ms 58552 KB Output is correct
28 Correct 451 ms 60264 KB Output is correct
29 Correct 429 ms 58896 KB Output is correct
30 Correct 380 ms 59528 KB Output is correct
31 Correct 424 ms 60244 KB Output is correct
32 Correct 395 ms 58172 KB Output is correct
33 Correct 434 ms 59596 KB Output is correct
34 Correct 717 ms 66324 KB Output is correct
35 Correct 429 ms 58832 KB Output is correct
36 Correct 282 ms 84068 KB Output is correct
37 Correct 320 ms 84152 KB Output is correct
38 Correct 733 ms 65916 KB Output is correct
39 Correct 700 ms 65684 KB Output is correct
40 Correct 837 ms 66732 KB Output is correct
41 Correct 362 ms 69472 KB Output is correct
42 Correct 361 ms 69444 KB Output is correct
43 Correct 358 ms 69500 KB Output is correct
44 Correct 361 ms 69488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21516 KB Output is correct
2 Correct 12 ms 21492 KB Output is correct
3 Correct 12 ms 21464 KB Output is correct
4 Correct 15 ms 21452 KB Output is correct
5 Correct 12 ms 21492 KB Output is correct
6 Correct 15 ms 21452 KB Output is correct
7 Correct 13 ms 21484 KB Output is correct
8 Correct 12 ms 21448 KB Output is correct
9 Correct 14 ms 21864 KB Output is correct
10 Correct 14 ms 21864 KB Output is correct
11 Correct 14 ms 21800 KB Output is correct
12 Correct 14 ms 21772 KB Output is correct
13 Correct 13 ms 21720 KB Output is correct
14 Correct 14 ms 21800 KB Output is correct
15 Correct 14 ms 21800 KB Output is correct
16 Correct 14 ms 21836 KB Output is correct
17 Correct 737 ms 70512 KB Output is correct
18 Correct 731 ms 69948 KB Output is correct
19 Correct 710 ms 70124 KB Output is correct
20 Correct 720 ms 70300 KB Output is correct
21 Correct 686 ms 70500 KB Output is correct
22 Correct 712 ms 71912 KB Output is correct
23 Correct 716 ms 71096 KB Output is correct
24 Correct 774 ms 71852 KB Output is correct
25 Correct 725 ms 72048 KB Output is correct
26 Correct 803 ms 70852 KB Output is correct
27 Correct 785 ms 69260 KB Output is correct
28 Correct 811 ms 71440 KB Output is correct
29 Correct 742 ms 71060 KB Output is correct
30 Correct 757 ms 71848 KB Output is correct
31 Correct 706 ms 71052 KB Output is correct
32 Correct 713 ms 71236 KB Output is correct
33 Correct 581 ms 65280 KB Output is correct
34 Correct 319 ms 69024 KB Output is correct
35 Correct 290 ms 60160 KB Output is correct
36 Correct 293 ms 58984 KB Output is correct
37 Correct 266 ms 58632 KB Output is correct
38 Correct 273 ms 59888 KB Output is correct
39 Correct 281 ms 58288 KB Output is correct
40 Correct 269 ms 58892 KB Output is correct
41 Correct 278 ms 57740 KB Output is correct
42 Correct 292 ms 60980 KB Output is correct
43 Correct 282 ms 58460 KB Output is correct
44 Correct 636 ms 65900 KB Output is correct
45 Correct 261 ms 58684 KB Output is correct
46 Correct 253 ms 81100 KB Output is correct
47 Correct 188 ms 71140 KB Output is correct
48 Correct 548 ms 64948 KB Output is correct
49 Correct 598 ms 65008 KB Output is correct
50 Correct 463 ms 63304 KB Output is correct
51 Correct 303 ms 69344 KB Output is correct
52 Correct 307 ms 69412 KB Output is correct
53 Correct 299 ms 69312 KB Output is correct
54 Correct 300 ms 69172 KB Output is correct
55 Correct 711 ms 66360 KB Output is correct
56 Correct 361 ms 69448 KB Output is correct
57 Correct 408 ms 59172 KB Output is correct
58 Correct 382 ms 58872 KB Output is correct
59 Correct 369 ms 58552 KB Output is correct
60 Correct 451 ms 60264 KB Output is correct
61 Correct 429 ms 58896 KB Output is correct
62 Correct 380 ms 59528 KB Output is correct
63 Correct 424 ms 60244 KB Output is correct
64 Correct 395 ms 58172 KB Output is correct
65 Correct 434 ms 59596 KB Output is correct
66 Correct 717 ms 66324 KB Output is correct
67 Correct 429 ms 58832 KB Output is correct
68 Correct 282 ms 84068 KB Output is correct
69 Correct 320 ms 84152 KB Output is correct
70 Correct 733 ms 65916 KB Output is correct
71 Correct 700 ms 65684 KB Output is correct
72 Correct 837 ms 66732 KB Output is correct
73 Correct 362 ms 69472 KB Output is correct
74 Correct 361 ms 69444 KB Output is correct
75 Correct 358 ms 69500 KB Output is correct
76 Correct 361 ms 69488 KB Output is correct
77 Correct 899 ms 66780 KB Output is correct
78 Correct 371 ms 69168 KB Output is correct
79 Correct 454 ms 59116 KB Output is correct
80 Correct 473 ms 57992 KB Output is correct
81 Correct 422 ms 59196 KB Output is correct
82 Correct 491 ms 58948 KB Output is correct
83 Correct 446 ms 58304 KB Output is correct
84 Correct 463 ms 58444 KB Output is correct
85 Correct 404 ms 59504 KB Output is correct
86 Correct 484 ms 59152 KB Output is correct
87 Correct 459 ms 58404 KB Output is correct
88 Correct 644 ms 65716 KB Output is correct
89 Correct 440 ms 59044 KB Output is correct
90 Correct 300 ms 83692 KB Output is correct
91 Correct 346 ms 83720 KB Output is correct
92 Runtime error 837 ms 134560 KB Execution killed with signal 6
93 Halted 0 ms 0 KB -