Submission #459644

# Submission time Handle Problem Language Result Execution time Memory
459644 2021-08-08T21:26:17 Z nickmet2004 Aesthetic (NOI20_aesthetic) C++11
73 / 100
801 ms 134576 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n , m ,A, au[300005] , av[300005] , aw[300005];
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[300005] , T[300005];
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]==1) S.erase(it);
        if(f[y.first] == 0) 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){
        ll 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();
        ll u = T.second , w = -T.first;
        if(f[u])continue;
        f[u] = 1;
        for(auto e : adj[u]){
            ll 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();
        ll u = T.second , w = -T.first;
        if(f[u])continue;
        f[u] = 1;
        for(auto e : adj[u]){
            ll 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";
    while(1){
        //cout << "ha";
        if(s == 1)break;
        for(ll v : T[s]) q(v);
        s = par[s];
        ll 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<<endl;

}

Compilation message

Aesthetic.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   24 | main (){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21452 KB Output is correct
2 Correct 12 ms 21496 KB Output is correct
3 Correct 12 ms 21500 KB Output is correct
4 Correct 13 ms 21516 KB Output is correct
5 Correct 14 ms 21448 KB Output is correct
6 Correct 12 ms 21532 KB Output is correct
7 Correct 12 ms 21452 KB Output is correct
8 Correct 12 ms 21496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21452 KB Output is correct
2 Correct 12 ms 21496 KB Output is correct
3 Correct 12 ms 21500 KB Output is correct
4 Correct 13 ms 21516 KB Output is correct
5 Correct 14 ms 21448 KB Output is correct
6 Correct 12 ms 21532 KB Output is correct
7 Correct 12 ms 21452 KB Output is correct
8 Correct 12 ms 21496 KB Output is correct
9 Correct 15 ms 21708 KB Output is correct
10 Correct 14 ms 21756 KB Output is correct
11 Correct 14 ms 21772 KB Output is correct
12 Correct 14 ms 21816 KB Output is correct
13 Correct 14 ms 21752 KB Output is correct
14 Correct 14 ms 21760 KB Output is correct
15 Correct 13 ms 21676 KB Output is correct
16 Correct 13 ms 21784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 707 ms 70152 KB Output is correct
2 Correct 702 ms 69788 KB Output is correct
3 Correct 723 ms 69752 KB Output is correct
4 Correct 705 ms 69912 KB Output is correct
5 Correct 688 ms 70200 KB Output is correct
6 Correct 716 ms 71400 KB Output is correct
7 Correct 723 ms 70732 KB Output is correct
8 Correct 743 ms 71508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 737 ms 71732 KB Output is correct
2 Correct 770 ms 70572 KB Output is correct
3 Correct 710 ms 68792 KB Output is correct
4 Correct 711 ms 70908 KB Output is correct
5 Correct 732 ms 70724 KB Output is correct
6 Correct 744 ms 71448 KB Output is correct
7 Correct 738 ms 70636 KB Output is correct
8 Correct 708 ms 70852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 533 ms 64960 KB Output is correct
2 Correct 305 ms 68972 KB Output is correct
3 Correct 287 ms 59896 KB Output is correct
4 Correct 261 ms 58676 KB Output is correct
5 Correct 267 ms 58432 KB Output is correct
6 Correct 275 ms 59692 KB Output is correct
7 Correct 253 ms 58016 KB Output is correct
8 Correct 264 ms 58476 KB Output is correct
9 Correct 258 ms 57548 KB Output is correct
10 Correct 295 ms 60628 KB Output is correct
11 Correct 258 ms 58152 KB Output is correct
12 Correct 634 ms 65636 KB Output is correct
13 Correct 262 ms 58428 KB Output is correct
14 Correct 248 ms 80908 KB Output is correct
15 Correct 180 ms 70732 KB Output is correct
16 Correct 540 ms 64752 KB Output is correct
17 Correct 617 ms 64652 KB Output is correct
18 Correct 490 ms 63048 KB Output is correct
19 Correct 303 ms 69060 KB Output is correct
20 Correct 306 ms 68992 KB Output is correct
21 Correct 319 ms 68968 KB Output is correct
22 Correct 299 ms 68992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 533 ms 64960 KB Output is correct
2 Correct 305 ms 68972 KB Output is correct
3 Correct 287 ms 59896 KB Output is correct
4 Correct 261 ms 58676 KB Output is correct
5 Correct 267 ms 58432 KB Output is correct
6 Correct 275 ms 59692 KB Output is correct
7 Correct 253 ms 58016 KB Output is correct
8 Correct 264 ms 58476 KB Output is correct
9 Correct 258 ms 57548 KB Output is correct
10 Correct 295 ms 60628 KB Output is correct
11 Correct 258 ms 58152 KB Output is correct
12 Correct 634 ms 65636 KB Output is correct
13 Correct 262 ms 58428 KB Output is correct
14 Correct 248 ms 80908 KB Output is correct
15 Correct 180 ms 70732 KB Output is correct
16 Correct 540 ms 64752 KB Output is correct
17 Correct 617 ms 64652 KB Output is correct
18 Correct 490 ms 63048 KB Output is correct
19 Correct 303 ms 69060 KB Output is correct
20 Correct 306 ms 68992 KB Output is correct
21 Correct 319 ms 68968 KB Output is correct
22 Correct 299 ms 68992 KB Output is correct
23 Correct 720 ms 66060 KB Output is correct
24 Correct 367 ms 69316 KB Output is correct
25 Correct 376 ms 58992 KB Output is correct
26 Correct 386 ms 58500 KB Output is correct
27 Correct 373 ms 58328 KB Output is correct
28 Correct 441 ms 60028 KB Output is correct
29 Correct 412 ms 58744 KB Output is correct
30 Correct 386 ms 59208 KB Output is correct
31 Correct 419 ms 59912 KB Output is correct
32 Correct 374 ms 57744 KB Output is correct
33 Correct 421 ms 59212 KB Output is correct
34 Correct 694 ms 65976 KB Output is correct
35 Correct 416 ms 58460 KB Output is correct
36 Correct 286 ms 83684 KB Output is correct
37 Correct 313 ms 83816 KB Output is correct
38 Correct 736 ms 65628 KB Output is correct
39 Correct 723 ms 65200 KB Output is correct
40 Correct 789 ms 66296 KB Output is correct
41 Correct 369 ms 69264 KB Output is correct
42 Correct 358 ms 69100 KB Output is correct
43 Correct 366 ms 69060 KB Output is correct
44 Correct 357 ms 69220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21452 KB Output is correct
2 Correct 12 ms 21496 KB Output is correct
3 Correct 12 ms 21500 KB Output is correct
4 Correct 13 ms 21516 KB Output is correct
5 Correct 14 ms 21448 KB Output is correct
6 Correct 12 ms 21532 KB Output is correct
7 Correct 12 ms 21452 KB Output is correct
8 Correct 12 ms 21496 KB Output is correct
9 Correct 15 ms 21708 KB Output is correct
10 Correct 14 ms 21756 KB Output is correct
11 Correct 14 ms 21772 KB Output is correct
12 Correct 14 ms 21816 KB Output is correct
13 Correct 14 ms 21752 KB Output is correct
14 Correct 14 ms 21760 KB Output is correct
15 Correct 13 ms 21676 KB Output is correct
16 Correct 13 ms 21784 KB Output is correct
17 Correct 707 ms 70152 KB Output is correct
18 Correct 702 ms 69788 KB Output is correct
19 Correct 723 ms 69752 KB Output is correct
20 Correct 705 ms 69912 KB Output is correct
21 Correct 688 ms 70200 KB Output is correct
22 Correct 716 ms 71400 KB Output is correct
23 Correct 723 ms 70732 KB Output is correct
24 Correct 743 ms 71508 KB Output is correct
25 Correct 737 ms 71732 KB Output is correct
26 Correct 770 ms 70572 KB Output is correct
27 Correct 710 ms 68792 KB Output is correct
28 Correct 711 ms 70908 KB Output is correct
29 Correct 732 ms 70724 KB Output is correct
30 Correct 744 ms 71448 KB Output is correct
31 Correct 738 ms 70636 KB Output is correct
32 Correct 708 ms 70852 KB Output is correct
33 Correct 533 ms 64960 KB Output is correct
34 Correct 305 ms 68972 KB Output is correct
35 Correct 287 ms 59896 KB Output is correct
36 Correct 261 ms 58676 KB Output is correct
37 Correct 267 ms 58432 KB Output is correct
38 Correct 275 ms 59692 KB Output is correct
39 Correct 253 ms 58016 KB Output is correct
40 Correct 264 ms 58476 KB Output is correct
41 Correct 258 ms 57548 KB Output is correct
42 Correct 295 ms 60628 KB Output is correct
43 Correct 258 ms 58152 KB Output is correct
44 Correct 634 ms 65636 KB Output is correct
45 Correct 262 ms 58428 KB Output is correct
46 Correct 248 ms 80908 KB Output is correct
47 Correct 180 ms 70732 KB Output is correct
48 Correct 540 ms 64752 KB Output is correct
49 Correct 617 ms 64652 KB Output is correct
50 Correct 490 ms 63048 KB Output is correct
51 Correct 303 ms 69060 KB Output is correct
52 Correct 306 ms 68992 KB Output is correct
53 Correct 319 ms 68968 KB Output is correct
54 Correct 299 ms 68992 KB Output is correct
55 Correct 720 ms 66060 KB Output is correct
56 Correct 367 ms 69316 KB Output is correct
57 Correct 376 ms 58992 KB Output is correct
58 Correct 386 ms 58500 KB Output is correct
59 Correct 373 ms 58328 KB Output is correct
60 Correct 441 ms 60028 KB Output is correct
61 Correct 412 ms 58744 KB Output is correct
62 Correct 386 ms 59208 KB Output is correct
63 Correct 419 ms 59912 KB Output is correct
64 Correct 374 ms 57744 KB Output is correct
65 Correct 421 ms 59212 KB Output is correct
66 Correct 694 ms 65976 KB Output is correct
67 Correct 416 ms 58460 KB Output is correct
68 Correct 286 ms 83684 KB Output is correct
69 Correct 313 ms 83816 KB Output is correct
70 Correct 736 ms 65628 KB Output is correct
71 Correct 723 ms 65200 KB Output is correct
72 Correct 789 ms 66296 KB Output is correct
73 Correct 369 ms 69264 KB Output is correct
74 Correct 358 ms 69100 KB Output is correct
75 Correct 366 ms 69060 KB Output is correct
76 Correct 357 ms 69220 KB Output is correct
77 Correct 801 ms 66712 KB Output is correct
78 Correct 364 ms 69100 KB Output is correct
79 Correct 468 ms 59132 KB Output is correct
80 Correct 453 ms 58024 KB Output is correct
81 Correct 432 ms 59128 KB Output is correct
82 Correct 476 ms 58868 KB Output is correct
83 Correct 452 ms 58252 KB Output is correct
84 Correct 460 ms 58332 KB Output is correct
85 Correct 428 ms 59464 KB Output is correct
86 Correct 449 ms 59116 KB Output is correct
87 Correct 438 ms 58372 KB Output is correct
88 Correct 659 ms 65700 KB Output is correct
89 Correct 428 ms 58888 KB Output is correct
90 Correct 324 ms 83624 KB Output is correct
91 Correct 351 ms 83816 KB Output is correct
92 Runtime error 786 ms 134576 KB Execution killed with signal 6
93 Halted 0 ms 0 KB -