답안 #459647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
459647 2021-08-08T21:35:46 Z nickmet2004 Aesthetic (NOI20_aesthetic) C++11
73 / 100
840 ms 134548 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n , m ,A, au[300002] , av[300002] , aw[300002];
vector<pair<ll, pair<ll , ll> > >  adj[300002];
ll d1[300002] , dn[300002] , f[300002] , par[300002] , path[300002] , son[300002];
multiset<pair<ll , ll>> S;
vector<ll> B[300002] , T[300002];
void q(ll x){
    f[x] = 1;
    for(auto j : adj[x]){
        //cout << "h";
        ll y = j.first , l = j.second.first;
        auto it = S.find({dn[y] + l + d1[x] , j.second.second});
        if(f[y]==1) S.erase(it);
        if(f[y] == 0) S.insert({dn[x] + l + d1[y] , j.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];
        if(S.size() == 0)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);
    }
    cout << ans<<endl;

}

Compilation message

Aesthetic.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main (){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21452 KB Output is correct
2 Correct 12 ms 21504 KB Output is correct
3 Correct 12 ms 21452 KB Output is correct
4 Correct 12 ms 21424 KB Output is correct
5 Correct 12 ms 21452 KB Output is correct
6 Correct 12 ms 21452 KB Output is correct
7 Correct 12 ms 21452 KB Output is correct
8 Correct 12 ms 21428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21452 KB Output is correct
2 Correct 12 ms 21504 KB Output is correct
3 Correct 12 ms 21452 KB Output is correct
4 Correct 12 ms 21424 KB Output is correct
5 Correct 12 ms 21452 KB Output is correct
6 Correct 12 ms 21452 KB Output is correct
7 Correct 12 ms 21452 KB Output is correct
8 Correct 12 ms 21428 KB Output is correct
9 Correct 17 ms 21768 KB Output is correct
10 Correct 14 ms 21844 KB Output is correct
11 Correct 14 ms 21764 KB Output is correct
12 Correct 14 ms 21744 KB Output is correct
13 Correct 15 ms 21776 KB Output is correct
14 Correct 14 ms 21768 KB Output is correct
15 Correct 13 ms 21744 KB Output is correct
16 Correct 13 ms 21708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 724 ms 70168 KB Output is correct
2 Correct 704 ms 69712 KB Output is correct
3 Correct 698 ms 69764 KB Output is correct
4 Correct 679 ms 69872 KB Output is correct
5 Correct 697 ms 70148 KB Output is correct
6 Correct 718 ms 71356 KB Output is correct
7 Correct 711 ms 70796 KB Output is correct
8 Correct 701 ms 71420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 719 ms 71680 KB Output is correct
2 Correct 725 ms 70580 KB Output is correct
3 Correct 735 ms 68972 KB Output is correct
4 Correct 769 ms 71024 KB Output is correct
5 Correct 746 ms 70668 KB Output is correct
6 Correct 703 ms 71472 KB Output is correct
7 Correct 728 ms 70668 KB Output is correct
8 Correct 707 ms 71076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 560 ms 65052 KB Output is correct
2 Correct 305 ms 68824 KB Output is correct
3 Correct 303 ms 59828 KB Output is correct
4 Correct 266 ms 58804 KB Output is correct
5 Correct 265 ms 58344 KB Output is correct
6 Correct 268 ms 59716 KB Output is correct
7 Correct 257 ms 58084 KB Output is correct
8 Correct 282 ms 58580 KB Output is correct
9 Correct 250 ms 57468 KB Output is correct
10 Correct 298 ms 60728 KB Output is correct
11 Correct 260 ms 58184 KB Output is correct
12 Correct 617 ms 65624 KB Output is correct
13 Correct 262 ms 58556 KB Output is correct
14 Correct 240 ms 80980 KB Output is correct
15 Correct 180 ms 70712 KB Output is correct
16 Correct 525 ms 64616 KB Output is correct
17 Correct 555 ms 64624 KB Output is correct
18 Correct 463 ms 63060 KB Output is correct
19 Correct 303 ms 68988 KB Output is correct
20 Correct 309 ms 69100 KB Output is correct
21 Correct 319 ms 69188 KB Output is correct
22 Correct 314 ms 69020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 560 ms 65052 KB Output is correct
2 Correct 305 ms 68824 KB Output is correct
3 Correct 303 ms 59828 KB Output is correct
4 Correct 266 ms 58804 KB Output is correct
5 Correct 265 ms 58344 KB Output is correct
6 Correct 268 ms 59716 KB Output is correct
7 Correct 257 ms 58084 KB Output is correct
8 Correct 282 ms 58580 KB Output is correct
9 Correct 250 ms 57468 KB Output is correct
10 Correct 298 ms 60728 KB Output is correct
11 Correct 260 ms 58184 KB Output is correct
12 Correct 617 ms 65624 KB Output is correct
13 Correct 262 ms 58556 KB Output is correct
14 Correct 240 ms 80980 KB Output is correct
15 Correct 180 ms 70712 KB Output is correct
16 Correct 525 ms 64616 KB Output is correct
17 Correct 555 ms 64624 KB Output is correct
18 Correct 463 ms 63060 KB Output is correct
19 Correct 303 ms 68988 KB Output is correct
20 Correct 309 ms 69100 KB Output is correct
21 Correct 319 ms 69188 KB Output is correct
22 Correct 314 ms 69020 KB Output is correct
23 Correct 728 ms 66216 KB Output is correct
24 Correct 366 ms 69344 KB Output is correct
25 Correct 378 ms 58904 KB Output is correct
26 Correct 374 ms 58580 KB Output is correct
27 Correct 349 ms 58304 KB Output is correct
28 Correct 432 ms 60000 KB Output is correct
29 Correct 409 ms 58732 KB Output is correct
30 Correct 376 ms 59240 KB Output is correct
31 Correct 408 ms 59864 KB Output is correct
32 Correct 386 ms 57772 KB Output is correct
33 Correct 440 ms 59328 KB Output is correct
34 Correct 719 ms 65924 KB Output is correct
35 Correct 407 ms 58408 KB Output is correct
36 Correct 292 ms 83716 KB Output is correct
37 Correct 311 ms 83716 KB Output is correct
38 Correct 671 ms 65568 KB Output is correct
39 Correct 700 ms 65240 KB Output is correct
40 Correct 770 ms 66276 KB Output is correct
41 Correct 363 ms 69116 KB Output is correct
42 Correct 362 ms 69176 KB Output is correct
43 Correct 359 ms 69136 KB Output is correct
44 Correct 361 ms 69148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21452 KB Output is correct
2 Correct 12 ms 21504 KB Output is correct
3 Correct 12 ms 21452 KB Output is correct
4 Correct 12 ms 21424 KB Output is correct
5 Correct 12 ms 21452 KB Output is correct
6 Correct 12 ms 21452 KB Output is correct
7 Correct 12 ms 21452 KB Output is correct
8 Correct 12 ms 21428 KB Output is correct
9 Correct 17 ms 21768 KB Output is correct
10 Correct 14 ms 21844 KB Output is correct
11 Correct 14 ms 21764 KB Output is correct
12 Correct 14 ms 21744 KB Output is correct
13 Correct 15 ms 21776 KB Output is correct
14 Correct 14 ms 21768 KB Output is correct
15 Correct 13 ms 21744 KB Output is correct
16 Correct 13 ms 21708 KB Output is correct
17 Correct 724 ms 70168 KB Output is correct
18 Correct 704 ms 69712 KB Output is correct
19 Correct 698 ms 69764 KB Output is correct
20 Correct 679 ms 69872 KB Output is correct
21 Correct 697 ms 70148 KB Output is correct
22 Correct 718 ms 71356 KB Output is correct
23 Correct 711 ms 70796 KB Output is correct
24 Correct 701 ms 71420 KB Output is correct
25 Correct 719 ms 71680 KB Output is correct
26 Correct 725 ms 70580 KB Output is correct
27 Correct 735 ms 68972 KB Output is correct
28 Correct 769 ms 71024 KB Output is correct
29 Correct 746 ms 70668 KB Output is correct
30 Correct 703 ms 71472 KB Output is correct
31 Correct 728 ms 70668 KB Output is correct
32 Correct 707 ms 71076 KB Output is correct
33 Correct 560 ms 65052 KB Output is correct
34 Correct 305 ms 68824 KB Output is correct
35 Correct 303 ms 59828 KB Output is correct
36 Correct 266 ms 58804 KB Output is correct
37 Correct 265 ms 58344 KB Output is correct
38 Correct 268 ms 59716 KB Output is correct
39 Correct 257 ms 58084 KB Output is correct
40 Correct 282 ms 58580 KB Output is correct
41 Correct 250 ms 57468 KB Output is correct
42 Correct 298 ms 60728 KB Output is correct
43 Correct 260 ms 58184 KB Output is correct
44 Correct 617 ms 65624 KB Output is correct
45 Correct 262 ms 58556 KB Output is correct
46 Correct 240 ms 80980 KB Output is correct
47 Correct 180 ms 70712 KB Output is correct
48 Correct 525 ms 64616 KB Output is correct
49 Correct 555 ms 64624 KB Output is correct
50 Correct 463 ms 63060 KB Output is correct
51 Correct 303 ms 68988 KB Output is correct
52 Correct 309 ms 69100 KB Output is correct
53 Correct 319 ms 69188 KB Output is correct
54 Correct 314 ms 69020 KB Output is correct
55 Correct 728 ms 66216 KB Output is correct
56 Correct 366 ms 69344 KB Output is correct
57 Correct 378 ms 58904 KB Output is correct
58 Correct 374 ms 58580 KB Output is correct
59 Correct 349 ms 58304 KB Output is correct
60 Correct 432 ms 60000 KB Output is correct
61 Correct 409 ms 58732 KB Output is correct
62 Correct 376 ms 59240 KB Output is correct
63 Correct 408 ms 59864 KB Output is correct
64 Correct 386 ms 57772 KB Output is correct
65 Correct 440 ms 59328 KB Output is correct
66 Correct 719 ms 65924 KB Output is correct
67 Correct 407 ms 58408 KB Output is correct
68 Correct 292 ms 83716 KB Output is correct
69 Correct 311 ms 83716 KB Output is correct
70 Correct 671 ms 65568 KB Output is correct
71 Correct 700 ms 65240 KB Output is correct
72 Correct 770 ms 66276 KB Output is correct
73 Correct 363 ms 69116 KB Output is correct
74 Correct 362 ms 69176 KB Output is correct
75 Correct 359 ms 69136 KB Output is correct
76 Correct 361 ms 69148 KB Output is correct
77 Correct 808 ms 66548 KB Output is correct
78 Correct 371 ms 69096 KB Output is correct
79 Correct 445 ms 59124 KB Output is correct
80 Correct 443 ms 57940 KB Output is correct
81 Correct 441 ms 59124 KB Output is correct
82 Correct 516 ms 58944 KB Output is correct
83 Correct 448 ms 58248 KB Output is correct
84 Correct 458 ms 58392 KB Output is correct
85 Correct 415 ms 59556 KB Output is correct
86 Correct 475 ms 59136 KB Output is correct
87 Correct 422 ms 58364 KB Output is correct
88 Correct 645 ms 65640 KB Output is correct
89 Correct 428 ms 58940 KB Output is correct
90 Correct 319 ms 83620 KB Output is correct
91 Correct 354 ms 83728 KB Output is correct
92 Runtime error 840 ms 134548 KB Execution killed with signal 6
93 Halted 0 ms 0 KB -