Submission #459614

# Submission time Handle Problem Language Result Execution time Memory
459614 2021-08-08T20:34:24 Z nickmet2004 Aesthetic (NOI20_aesthetic) C++11
73 / 100
808 ms 136068 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 1;
ll n , m , au[N] , av[N] , aw[N];
ll u , v , w , A = 0;
vector<pair<ll, pair<ll , ll> > >  adj[N];
ll d1[N] , dn[N] , f[N] , par[N] , path[N] , son[N];
priority_queue<pair<ll , ll> > pq;
multiset<pair<ll , ll>> S;
vector<ll> B[N] , T[N];
void q(int 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;
    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";
    }

    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);

    memset(f , 0 ,sizeof(f));
    u = n;
    ll ans = d1[n];
    //cout << "ka";

    while(1){
        //cout << "ha";
        if(u == 1)break;
        for(ll v : T[u]) q(v);
        //if(!S.size())continue;
        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);
        u = par[u];
    }
    cout << ans;

}

Compilation message

Aesthetic.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main (){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23748 KB Output is correct
2 Correct 13 ms 23888 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23772 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 13 ms 23756 KB Output is correct
8 Correct 13 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23748 KB Output is correct
2 Correct 13 ms 23888 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23772 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 13 ms 23756 KB Output is correct
8 Correct 13 ms 23756 KB Output is correct
9 Correct 15 ms 24092 KB Output is correct
10 Correct 15 ms 24172 KB Output is correct
11 Correct 15 ms 24080 KB Output is correct
12 Correct 15 ms 24132 KB Output is correct
13 Correct 14 ms 24092 KB Output is correct
14 Correct 15 ms 24140 KB Output is correct
15 Correct 14 ms 24168 KB Output is correct
16 Correct 14 ms 24140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 718 ms 70724 KB Output is correct
2 Correct 709 ms 70100 KB Output is correct
3 Correct 701 ms 70284 KB Output is correct
4 Correct 725 ms 70404 KB Output is correct
5 Correct 689 ms 70712 KB Output is correct
6 Correct 717 ms 71892 KB Output is correct
7 Correct 738 ms 71288 KB Output is correct
8 Correct 738 ms 71964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 744 ms 72236 KB Output is correct
2 Correct 700 ms 71112 KB Output is correct
3 Correct 723 ms 69432 KB Output is correct
4 Correct 732 ms 71512 KB Output is correct
5 Correct 738 ms 71236 KB Output is correct
6 Correct 739 ms 72016 KB Output is correct
7 Correct 781 ms 71192 KB Output is correct
8 Correct 709 ms 71380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 569 ms 66068 KB Output is correct
2 Correct 295 ms 69572 KB Output is correct
3 Correct 330 ms 61756 KB Output is correct
4 Correct 260 ms 60752 KB Output is correct
5 Correct 276 ms 60444 KB Output is correct
6 Correct 271 ms 61628 KB Output is correct
7 Correct 270 ms 59968 KB Output is correct
8 Correct 299 ms 60544 KB Output is correct
9 Correct 274 ms 59368 KB Output is correct
10 Correct 292 ms 62656 KB Output is correct
11 Correct 280 ms 60132 KB Output is correct
12 Correct 621 ms 66820 KB Output is correct
13 Correct 279 ms 60440 KB Output is correct
14 Correct 242 ms 82176 KB Output is correct
15 Correct 208 ms 71872 KB Output is correct
16 Correct 484 ms 65808 KB Output is correct
17 Correct 604 ms 66004 KB Output is correct
18 Correct 459 ms 64200 KB Output is correct
19 Correct 297 ms 69744 KB Output is correct
20 Correct 300 ms 69708 KB Output is correct
21 Correct 310 ms 69832 KB Output is correct
22 Correct 297 ms 69668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 569 ms 66068 KB Output is correct
2 Correct 295 ms 69572 KB Output is correct
3 Correct 330 ms 61756 KB Output is correct
4 Correct 260 ms 60752 KB Output is correct
5 Correct 276 ms 60444 KB Output is correct
6 Correct 271 ms 61628 KB Output is correct
7 Correct 270 ms 59968 KB Output is correct
8 Correct 299 ms 60544 KB Output is correct
9 Correct 274 ms 59368 KB Output is correct
10 Correct 292 ms 62656 KB Output is correct
11 Correct 280 ms 60132 KB Output is correct
12 Correct 621 ms 66820 KB Output is correct
13 Correct 279 ms 60440 KB Output is correct
14 Correct 242 ms 82176 KB Output is correct
15 Correct 208 ms 71872 KB Output is correct
16 Correct 484 ms 65808 KB Output is correct
17 Correct 604 ms 66004 KB Output is correct
18 Correct 459 ms 64200 KB Output is correct
19 Correct 297 ms 69744 KB Output is correct
20 Correct 300 ms 69708 KB Output is correct
21 Correct 310 ms 69832 KB Output is correct
22 Correct 297 ms 69668 KB Output is correct
23 Correct 699 ms 67204 KB Output is correct
24 Correct 361 ms 69928 KB Output is correct
25 Correct 374 ms 60860 KB Output is correct
26 Correct 386 ms 60556 KB Output is correct
27 Correct 345 ms 60252 KB Output is correct
28 Correct 429 ms 61920 KB Output is correct
29 Correct 411 ms 60624 KB Output is correct
30 Correct 376 ms 61216 KB Output is correct
31 Correct 416 ms 61816 KB Output is correct
32 Correct 392 ms 59716 KB Output is correct
33 Correct 442 ms 61212 KB Output is correct
34 Correct 702 ms 67172 KB Output is correct
35 Correct 401 ms 60240 KB Output is correct
36 Correct 302 ms 85156 KB Output is correct
37 Correct 310 ms 85140 KB Output is correct
38 Correct 673 ms 66504 KB Output is correct
39 Correct 789 ms 66220 KB Output is correct
40 Correct 774 ms 67404 KB Output is correct
41 Correct 360 ms 69684 KB Output is correct
42 Correct 357 ms 69856 KB Output is correct
43 Correct 365 ms 69736 KB Output is correct
44 Correct 362 ms 69704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23748 KB Output is correct
2 Correct 13 ms 23888 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23772 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 13 ms 23756 KB Output is correct
7 Correct 13 ms 23756 KB Output is correct
8 Correct 13 ms 23756 KB Output is correct
9 Correct 15 ms 24092 KB Output is correct
10 Correct 15 ms 24172 KB Output is correct
11 Correct 15 ms 24080 KB Output is correct
12 Correct 15 ms 24132 KB Output is correct
13 Correct 14 ms 24092 KB Output is correct
14 Correct 15 ms 24140 KB Output is correct
15 Correct 14 ms 24168 KB Output is correct
16 Correct 14 ms 24140 KB Output is correct
17 Correct 718 ms 70724 KB Output is correct
18 Correct 709 ms 70100 KB Output is correct
19 Correct 701 ms 70284 KB Output is correct
20 Correct 725 ms 70404 KB Output is correct
21 Correct 689 ms 70712 KB Output is correct
22 Correct 717 ms 71892 KB Output is correct
23 Correct 738 ms 71288 KB Output is correct
24 Correct 738 ms 71964 KB Output is correct
25 Correct 744 ms 72236 KB Output is correct
26 Correct 700 ms 71112 KB Output is correct
27 Correct 723 ms 69432 KB Output is correct
28 Correct 732 ms 71512 KB Output is correct
29 Correct 738 ms 71236 KB Output is correct
30 Correct 739 ms 72016 KB Output is correct
31 Correct 781 ms 71192 KB Output is correct
32 Correct 709 ms 71380 KB Output is correct
33 Correct 569 ms 66068 KB Output is correct
34 Correct 295 ms 69572 KB Output is correct
35 Correct 330 ms 61756 KB Output is correct
36 Correct 260 ms 60752 KB Output is correct
37 Correct 276 ms 60444 KB Output is correct
38 Correct 271 ms 61628 KB Output is correct
39 Correct 270 ms 59968 KB Output is correct
40 Correct 299 ms 60544 KB Output is correct
41 Correct 274 ms 59368 KB Output is correct
42 Correct 292 ms 62656 KB Output is correct
43 Correct 280 ms 60132 KB Output is correct
44 Correct 621 ms 66820 KB Output is correct
45 Correct 279 ms 60440 KB Output is correct
46 Correct 242 ms 82176 KB Output is correct
47 Correct 208 ms 71872 KB Output is correct
48 Correct 484 ms 65808 KB Output is correct
49 Correct 604 ms 66004 KB Output is correct
50 Correct 459 ms 64200 KB Output is correct
51 Correct 297 ms 69744 KB Output is correct
52 Correct 300 ms 69708 KB Output is correct
53 Correct 310 ms 69832 KB Output is correct
54 Correct 297 ms 69668 KB Output is correct
55 Correct 699 ms 67204 KB Output is correct
56 Correct 361 ms 69928 KB Output is correct
57 Correct 374 ms 60860 KB Output is correct
58 Correct 386 ms 60556 KB Output is correct
59 Correct 345 ms 60252 KB Output is correct
60 Correct 429 ms 61920 KB Output is correct
61 Correct 411 ms 60624 KB Output is correct
62 Correct 376 ms 61216 KB Output is correct
63 Correct 416 ms 61816 KB Output is correct
64 Correct 392 ms 59716 KB Output is correct
65 Correct 442 ms 61212 KB Output is correct
66 Correct 702 ms 67172 KB Output is correct
67 Correct 401 ms 60240 KB Output is correct
68 Correct 302 ms 85156 KB Output is correct
69 Correct 310 ms 85140 KB Output is correct
70 Correct 673 ms 66504 KB Output is correct
71 Correct 789 ms 66220 KB Output is correct
72 Correct 774 ms 67404 KB Output is correct
73 Correct 360 ms 69684 KB Output is correct
74 Correct 357 ms 69856 KB Output is correct
75 Correct 365 ms 69736 KB Output is correct
76 Correct 362 ms 69704 KB Output is correct
77 Correct 808 ms 67648 KB Output is correct
78 Correct 361 ms 69692 KB Output is correct
79 Correct 454 ms 60952 KB Output is correct
80 Correct 457 ms 59732 KB Output is correct
81 Correct 430 ms 61012 KB Output is correct
82 Correct 478 ms 60684 KB Output is correct
83 Correct 459 ms 59988 KB Output is correct
84 Correct 488 ms 60148 KB Output is correct
85 Correct 410 ms 61124 KB Output is correct
86 Correct 433 ms 60844 KB Output is correct
87 Correct 423 ms 60052 KB Output is correct
88 Correct 615 ms 66484 KB Output is correct
89 Correct 447 ms 60604 KB Output is correct
90 Correct 314 ms 84988 KB Output is correct
91 Correct 357 ms 84996 KB Output is correct
92 Runtime error 781 ms 136068 KB Execution killed with signal 6
93 Halted 0 ms 0 KB -