답안 #459648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
459648 2021-08-08T21:48:04 Z nickmet2004 Aesthetic (NOI20_aesthetic) C++11
73 / 100
880 ms 134528 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()){
        ll u = pq.top().second;
        pq.pop();
        if(f[u])continue;
        f[u] = 1;
        for(auto e : adj[u]){
            ll v = e.first , l = e.second.first;
            if(!f[v] && d1[v] > d1[u] + l){
                par[v] = u;
                d1[v] = d1[u] + l;
                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()){
        ll u = pq.top().second;
        pq.pop();
        if(f[u])continue;
        f[u] = 1;
        for(auto e : adj[u]){
            ll v = e.first , l = e.second.first;
            if(!f[v] && dn[v] > dn[u] + l){
                dn[v]= dn[u] + l;
                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:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main (){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 21452 KB Output is correct
2 Correct 12 ms 21452 KB Output is correct
3 Correct 12 ms 21452 KB Output is correct
4 Correct 12 ms 21484 KB Output is correct
5 Correct 12 ms 21452 KB Output is correct
6 Correct 12 ms 21452 KB Output is correct
7 Correct 13 ms 21492 KB Output is correct
8 Correct 12 ms 21524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 21452 KB Output is correct
2 Correct 12 ms 21452 KB Output is correct
3 Correct 12 ms 21452 KB Output is correct
4 Correct 12 ms 21484 KB Output is correct
5 Correct 12 ms 21452 KB Output is correct
6 Correct 12 ms 21452 KB Output is correct
7 Correct 13 ms 21492 KB Output is correct
8 Correct 12 ms 21524 KB Output is correct
9 Correct 14 ms 21708 KB Output is correct
10 Correct 14 ms 21836 KB Output is correct
11 Correct 14 ms 21700 KB Output is correct
12 Correct 14 ms 21752 KB Output is correct
13 Correct 13 ms 21716 KB Output is correct
14 Correct 14 ms 21708 KB Output is correct
15 Correct 16 ms 21708 KB Output is correct
16 Correct 16 ms 21748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 726 ms 70176 KB Output is correct
2 Correct 741 ms 69620 KB Output is correct
3 Correct 727 ms 69936 KB Output is correct
4 Correct 723 ms 69804 KB Output is correct
5 Correct 729 ms 70284 KB Output is correct
6 Correct 754 ms 71400 KB Output is correct
7 Correct 699 ms 70732 KB Output is correct
8 Correct 746 ms 71440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 727 ms 71664 KB Output is correct
2 Correct 702 ms 70548 KB Output is correct
3 Correct 733 ms 68872 KB Output is correct
4 Correct 717 ms 70996 KB Output is correct
5 Correct 710 ms 70712 KB Output is correct
6 Correct 703 ms 71452 KB Output is correct
7 Correct 714 ms 70600 KB Output is correct
8 Correct 747 ms 70864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 552 ms 64936 KB Output is correct
2 Correct 297 ms 68856 KB Output is correct
3 Correct 304 ms 60040 KB Output is correct
4 Correct 289 ms 58744 KB Output is correct
5 Correct 256 ms 58336 KB Output is correct
6 Correct 279 ms 59668 KB Output is correct
7 Correct 254 ms 58076 KB Output is correct
8 Correct 288 ms 58588 KB Output is correct
9 Correct 262 ms 57544 KB Output is correct
10 Correct 311 ms 60592 KB Output is correct
11 Correct 258 ms 58144 KB Output is correct
12 Correct 605 ms 65608 KB Output is correct
13 Correct 258 ms 58432 KB Output is correct
14 Correct 245 ms 80904 KB Output is correct
15 Correct 180 ms 70728 KB Output is correct
16 Correct 487 ms 64824 KB Output is correct
17 Correct 551 ms 64644 KB Output is correct
18 Correct 520 ms 63040 KB Output is correct
19 Correct 299 ms 69088 KB Output is correct
20 Correct 300 ms 69152 KB Output is correct
21 Correct 311 ms 69004 KB Output is correct
22 Correct 301 ms 69100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 552 ms 64936 KB Output is correct
2 Correct 297 ms 68856 KB Output is correct
3 Correct 304 ms 60040 KB Output is correct
4 Correct 289 ms 58744 KB Output is correct
5 Correct 256 ms 58336 KB Output is correct
6 Correct 279 ms 59668 KB Output is correct
7 Correct 254 ms 58076 KB Output is correct
8 Correct 288 ms 58588 KB Output is correct
9 Correct 262 ms 57544 KB Output is correct
10 Correct 311 ms 60592 KB Output is correct
11 Correct 258 ms 58144 KB Output is correct
12 Correct 605 ms 65608 KB Output is correct
13 Correct 258 ms 58432 KB Output is correct
14 Correct 245 ms 80904 KB Output is correct
15 Correct 180 ms 70728 KB Output is correct
16 Correct 487 ms 64824 KB Output is correct
17 Correct 551 ms 64644 KB Output is correct
18 Correct 520 ms 63040 KB Output is correct
19 Correct 299 ms 69088 KB Output is correct
20 Correct 300 ms 69152 KB Output is correct
21 Correct 311 ms 69004 KB Output is correct
22 Correct 301 ms 69100 KB Output is correct
23 Correct 723 ms 66104 KB Output is correct
24 Correct 357 ms 69220 KB Output is correct
25 Correct 370 ms 58972 KB Output is correct
26 Correct 380 ms 58488 KB Output is correct
27 Correct 349 ms 58280 KB Output is correct
28 Correct 429 ms 60036 KB Output is correct
29 Correct 426 ms 58712 KB Output is correct
30 Correct 362 ms 59184 KB Output is correct
31 Correct 409 ms 59816 KB Output is correct
32 Correct 368 ms 57728 KB Output is correct
33 Correct 418 ms 59200 KB Output is correct
34 Correct 691 ms 65976 KB Output is correct
35 Correct 416 ms 58584 KB Output is correct
36 Correct 285 ms 83656 KB Output is correct
37 Correct 307 ms 83716 KB Output is correct
38 Correct 682 ms 65500 KB Output is correct
39 Correct 689 ms 65212 KB Output is correct
40 Correct 788 ms 66272 KB Output is correct
41 Correct 358 ms 69204 KB Output is correct
42 Correct 356 ms 69068 KB Output is correct
43 Correct 352 ms 69184 KB Output is correct
44 Correct 352 ms 69052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 21452 KB Output is correct
2 Correct 12 ms 21452 KB Output is correct
3 Correct 12 ms 21452 KB Output is correct
4 Correct 12 ms 21484 KB Output is correct
5 Correct 12 ms 21452 KB Output is correct
6 Correct 12 ms 21452 KB Output is correct
7 Correct 13 ms 21492 KB Output is correct
8 Correct 12 ms 21524 KB Output is correct
9 Correct 14 ms 21708 KB Output is correct
10 Correct 14 ms 21836 KB Output is correct
11 Correct 14 ms 21700 KB Output is correct
12 Correct 14 ms 21752 KB Output is correct
13 Correct 13 ms 21716 KB Output is correct
14 Correct 14 ms 21708 KB Output is correct
15 Correct 16 ms 21708 KB Output is correct
16 Correct 16 ms 21748 KB Output is correct
17 Correct 726 ms 70176 KB Output is correct
18 Correct 741 ms 69620 KB Output is correct
19 Correct 727 ms 69936 KB Output is correct
20 Correct 723 ms 69804 KB Output is correct
21 Correct 729 ms 70284 KB Output is correct
22 Correct 754 ms 71400 KB Output is correct
23 Correct 699 ms 70732 KB Output is correct
24 Correct 746 ms 71440 KB Output is correct
25 Correct 727 ms 71664 KB Output is correct
26 Correct 702 ms 70548 KB Output is correct
27 Correct 733 ms 68872 KB Output is correct
28 Correct 717 ms 70996 KB Output is correct
29 Correct 710 ms 70712 KB Output is correct
30 Correct 703 ms 71452 KB Output is correct
31 Correct 714 ms 70600 KB Output is correct
32 Correct 747 ms 70864 KB Output is correct
33 Correct 552 ms 64936 KB Output is correct
34 Correct 297 ms 68856 KB Output is correct
35 Correct 304 ms 60040 KB Output is correct
36 Correct 289 ms 58744 KB Output is correct
37 Correct 256 ms 58336 KB Output is correct
38 Correct 279 ms 59668 KB Output is correct
39 Correct 254 ms 58076 KB Output is correct
40 Correct 288 ms 58588 KB Output is correct
41 Correct 262 ms 57544 KB Output is correct
42 Correct 311 ms 60592 KB Output is correct
43 Correct 258 ms 58144 KB Output is correct
44 Correct 605 ms 65608 KB Output is correct
45 Correct 258 ms 58432 KB Output is correct
46 Correct 245 ms 80904 KB Output is correct
47 Correct 180 ms 70728 KB Output is correct
48 Correct 487 ms 64824 KB Output is correct
49 Correct 551 ms 64644 KB Output is correct
50 Correct 520 ms 63040 KB Output is correct
51 Correct 299 ms 69088 KB Output is correct
52 Correct 300 ms 69152 KB Output is correct
53 Correct 311 ms 69004 KB Output is correct
54 Correct 301 ms 69100 KB Output is correct
55 Correct 723 ms 66104 KB Output is correct
56 Correct 357 ms 69220 KB Output is correct
57 Correct 370 ms 58972 KB Output is correct
58 Correct 380 ms 58488 KB Output is correct
59 Correct 349 ms 58280 KB Output is correct
60 Correct 429 ms 60036 KB Output is correct
61 Correct 426 ms 58712 KB Output is correct
62 Correct 362 ms 59184 KB Output is correct
63 Correct 409 ms 59816 KB Output is correct
64 Correct 368 ms 57728 KB Output is correct
65 Correct 418 ms 59200 KB Output is correct
66 Correct 691 ms 65976 KB Output is correct
67 Correct 416 ms 58584 KB Output is correct
68 Correct 285 ms 83656 KB Output is correct
69 Correct 307 ms 83716 KB Output is correct
70 Correct 682 ms 65500 KB Output is correct
71 Correct 689 ms 65212 KB Output is correct
72 Correct 788 ms 66272 KB Output is correct
73 Correct 358 ms 69204 KB Output is correct
74 Correct 356 ms 69068 KB Output is correct
75 Correct 352 ms 69184 KB Output is correct
76 Correct 352 ms 69052 KB Output is correct
77 Correct 880 ms 66656 KB Output is correct
78 Correct 372 ms 69252 KB Output is correct
79 Correct 444 ms 59068 KB Output is correct
80 Correct 450 ms 58000 KB Output is correct
81 Correct 475 ms 59116 KB Output is correct
82 Correct 516 ms 58996 KB Output is correct
83 Correct 442 ms 58248 KB Output is correct
84 Correct 464 ms 58464 KB Output is correct
85 Correct 415 ms 59456 KB Output is correct
86 Correct 441 ms 59028 KB Output is correct
87 Correct 439 ms 58424 KB Output is correct
88 Correct 611 ms 65596 KB Output is correct
89 Correct 429 ms 59068 KB Output is correct
90 Correct 322 ms 83668 KB Output is correct
91 Correct 369 ms 83840 KB Output is correct
92 Runtime error 813 ms 134528 KB Execution killed with signal 6
93 Halted 0 ms 0 KB -