답안 #464608

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
464608 2021-08-13T14:09:00 Z nickmet2004 Aesthetic (NOI20_aesthetic) C++11
100 / 100
899 ms 89812 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];
        if(u!= v){
        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(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(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 (){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23884 KB Output is correct
2 Correct 14 ms 23768 KB Output is correct
3 Correct 13 ms 23868 KB Output is correct
4 Correct 13 ms 23884 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 16 ms 23884 KB Output is correct
7 Correct 15 ms 23772 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23884 KB Output is correct
2 Correct 14 ms 23768 KB Output is correct
3 Correct 13 ms 23868 KB Output is correct
4 Correct 13 ms 23884 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 16 ms 23884 KB Output is correct
7 Correct 15 ms 23772 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
9 Correct 15 ms 24188 KB Output is correct
10 Correct 15 ms 24096 KB Output is correct
11 Correct 15 ms 24168 KB Output is correct
12 Correct 15 ms 24112 KB Output is correct
13 Correct 15 ms 24140 KB Output is correct
14 Correct 15 ms 24036 KB Output is correct
15 Correct 15 ms 24140 KB Output is correct
16 Correct 15 ms 24140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 736 ms 76912 KB Output is correct
2 Correct 738 ms 76316 KB Output is correct
3 Correct 754 ms 76368 KB Output is correct
4 Correct 723 ms 76508 KB Output is correct
5 Correct 775 ms 76904 KB Output is correct
6 Correct 732 ms 78160 KB Output is correct
7 Correct 782 ms 77476 KB Output is correct
8 Correct 730 ms 78312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 712 ms 78416 KB Output is correct
2 Correct 768 ms 77244 KB Output is correct
3 Correct 718 ms 75448 KB Output is correct
4 Correct 740 ms 77748 KB Output is correct
5 Correct 698 ms 77276 KB Output is correct
6 Correct 707 ms 78216 KB Output is correct
7 Correct 725 ms 77264 KB Output is correct
8 Correct 714 ms 77568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 571 ms 69968 KB Output is correct
2 Correct 311 ms 73620 KB Output is correct
3 Correct 328 ms 65420 KB Output is correct
4 Correct 279 ms 64300 KB Output is correct
5 Correct 281 ms 64000 KB Output is correct
6 Correct 308 ms 65252 KB Output is correct
7 Correct 256 ms 63584 KB Output is correct
8 Correct 262 ms 64060 KB Output is correct
9 Correct 251 ms 63036 KB Output is correct
10 Correct 291 ms 66196 KB Output is correct
11 Correct 283 ms 63704 KB Output is correct
12 Correct 718 ms 70732 KB Output is correct
13 Correct 316 ms 64060 KB Output is correct
14 Correct 236 ms 86036 KB Output is correct
15 Correct 195 ms 75900 KB Output is correct
16 Correct 546 ms 69872 KB Output is correct
17 Correct 587 ms 69724 KB Output is correct
18 Correct 527 ms 68108 KB Output is correct
19 Correct 338 ms 73804 KB Output is correct
20 Correct 324 ms 73832 KB Output is correct
21 Correct 316 ms 73796 KB Output is correct
22 Correct 334 ms 73832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 571 ms 69968 KB Output is correct
2 Correct 311 ms 73620 KB Output is correct
3 Correct 328 ms 65420 KB Output is correct
4 Correct 279 ms 64300 KB Output is correct
5 Correct 281 ms 64000 KB Output is correct
6 Correct 308 ms 65252 KB Output is correct
7 Correct 256 ms 63584 KB Output is correct
8 Correct 262 ms 64060 KB Output is correct
9 Correct 251 ms 63036 KB Output is correct
10 Correct 291 ms 66196 KB Output is correct
11 Correct 283 ms 63704 KB Output is correct
12 Correct 718 ms 70732 KB Output is correct
13 Correct 316 ms 64060 KB Output is correct
14 Correct 236 ms 86036 KB Output is correct
15 Correct 195 ms 75900 KB Output is correct
16 Correct 546 ms 69872 KB Output is correct
17 Correct 587 ms 69724 KB Output is correct
18 Correct 527 ms 68108 KB Output is correct
19 Correct 338 ms 73804 KB Output is correct
20 Correct 324 ms 73832 KB Output is correct
21 Correct 316 ms 73796 KB Output is correct
22 Correct 334 ms 73832 KB Output is correct
23 Correct 776 ms 71160 KB Output is correct
24 Correct 382 ms 73944 KB Output is correct
25 Correct 408 ms 64596 KB Output is correct
26 Correct 384 ms 64068 KB Output is correct
27 Correct 391 ms 63944 KB Output is correct
28 Correct 450 ms 65592 KB Output is correct
29 Correct 431 ms 64300 KB Output is correct
30 Correct 385 ms 64744 KB Output is correct
31 Correct 440 ms 65584 KB Output is correct
32 Correct 403 ms 63320 KB Output is correct
33 Correct 443 ms 64960 KB Output is correct
34 Correct 746 ms 70964 KB Output is correct
35 Correct 436 ms 64072 KB Output is correct
36 Correct 314 ms 88400 KB Output is correct
37 Correct 309 ms 89204 KB Output is correct
38 Correct 692 ms 70628 KB Output is correct
39 Correct 711 ms 70236 KB Output is correct
40 Correct 832 ms 71352 KB Output is correct
41 Correct 370 ms 73964 KB Output is correct
42 Correct 370 ms 73988 KB Output is correct
43 Correct 371 ms 73916 KB Output is correct
44 Correct 387 ms 73916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23884 KB Output is correct
2 Correct 14 ms 23768 KB Output is correct
3 Correct 13 ms 23868 KB Output is correct
4 Correct 13 ms 23884 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 16 ms 23884 KB Output is correct
7 Correct 15 ms 23772 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
9 Correct 15 ms 24188 KB Output is correct
10 Correct 15 ms 24096 KB Output is correct
11 Correct 15 ms 24168 KB Output is correct
12 Correct 15 ms 24112 KB Output is correct
13 Correct 15 ms 24140 KB Output is correct
14 Correct 15 ms 24036 KB Output is correct
15 Correct 15 ms 24140 KB Output is correct
16 Correct 15 ms 24140 KB Output is correct
17 Correct 736 ms 76912 KB Output is correct
18 Correct 738 ms 76316 KB Output is correct
19 Correct 754 ms 76368 KB Output is correct
20 Correct 723 ms 76508 KB Output is correct
21 Correct 775 ms 76904 KB Output is correct
22 Correct 732 ms 78160 KB Output is correct
23 Correct 782 ms 77476 KB Output is correct
24 Correct 730 ms 78312 KB Output is correct
25 Correct 712 ms 78416 KB Output is correct
26 Correct 768 ms 77244 KB Output is correct
27 Correct 718 ms 75448 KB Output is correct
28 Correct 740 ms 77748 KB Output is correct
29 Correct 698 ms 77276 KB Output is correct
30 Correct 707 ms 78216 KB Output is correct
31 Correct 725 ms 77264 KB Output is correct
32 Correct 714 ms 77568 KB Output is correct
33 Correct 571 ms 69968 KB Output is correct
34 Correct 311 ms 73620 KB Output is correct
35 Correct 328 ms 65420 KB Output is correct
36 Correct 279 ms 64300 KB Output is correct
37 Correct 281 ms 64000 KB Output is correct
38 Correct 308 ms 65252 KB Output is correct
39 Correct 256 ms 63584 KB Output is correct
40 Correct 262 ms 64060 KB Output is correct
41 Correct 251 ms 63036 KB Output is correct
42 Correct 291 ms 66196 KB Output is correct
43 Correct 283 ms 63704 KB Output is correct
44 Correct 718 ms 70732 KB Output is correct
45 Correct 316 ms 64060 KB Output is correct
46 Correct 236 ms 86036 KB Output is correct
47 Correct 195 ms 75900 KB Output is correct
48 Correct 546 ms 69872 KB Output is correct
49 Correct 587 ms 69724 KB Output is correct
50 Correct 527 ms 68108 KB Output is correct
51 Correct 338 ms 73804 KB Output is correct
52 Correct 324 ms 73832 KB Output is correct
53 Correct 316 ms 73796 KB Output is correct
54 Correct 334 ms 73832 KB Output is correct
55 Correct 776 ms 71160 KB Output is correct
56 Correct 382 ms 73944 KB Output is correct
57 Correct 408 ms 64596 KB Output is correct
58 Correct 384 ms 64068 KB Output is correct
59 Correct 391 ms 63944 KB Output is correct
60 Correct 450 ms 65592 KB Output is correct
61 Correct 431 ms 64300 KB Output is correct
62 Correct 385 ms 64744 KB Output is correct
63 Correct 440 ms 65584 KB Output is correct
64 Correct 403 ms 63320 KB Output is correct
65 Correct 443 ms 64960 KB Output is correct
66 Correct 746 ms 70964 KB Output is correct
67 Correct 436 ms 64072 KB Output is correct
68 Correct 314 ms 88400 KB Output is correct
69 Correct 309 ms 89204 KB Output is correct
70 Correct 692 ms 70628 KB Output is correct
71 Correct 711 ms 70236 KB Output is correct
72 Correct 832 ms 71352 KB Output is correct
73 Correct 370 ms 73964 KB Output is correct
74 Correct 370 ms 73988 KB Output is correct
75 Correct 371 ms 73916 KB Output is correct
76 Correct 387 ms 73916 KB Output is correct
77 Correct 899 ms 74040 KB Output is correct
78 Correct 399 ms 76352 KB Output is correct
79 Correct 488 ms 66980 KB Output is correct
80 Correct 479 ms 65808 KB Output is correct
81 Correct 453 ms 67008 KB Output is correct
82 Correct 493 ms 66808 KB Output is correct
83 Correct 446 ms 66156 KB Output is correct
84 Correct 470 ms 66428 KB Output is correct
85 Correct 414 ms 67388 KB Output is correct
86 Correct 454 ms 66948 KB Output is correct
87 Correct 442 ms 66308 KB Output is correct
88 Correct 641 ms 72884 KB Output is correct
89 Correct 435 ms 66796 KB Output is correct
90 Correct 326 ms 89080 KB Output is correct
91 Correct 347 ms 89812 KB Output is correct
92 Correct 831 ms 73740 KB Output is correct
93 Correct 601 ms 72268 KB Output is correct
94 Correct 609 ms 71464 KB Output is correct
95 Correct 378 ms 76292 KB Output is correct
96 Correct 372 ms 76312 KB Output is correct
97 Correct 370 ms 76208 KB Output is correct
98 Correct 373 ms 76100 KB Output is correct