답안 #459615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
459615 2021-08-08T20:37:08 Z nickmet2004 Aesthetic (NOI20_aesthetic) C++11
73 / 100
818 ms 136088 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 5;
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 (){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 13 ms 23884 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 13 ms 23876 KB Output is correct
7 Correct 13 ms 23836 KB Output is correct
8 Correct 13 ms 23756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 13 ms 23884 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 13 ms 23876 KB Output is correct
7 Correct 13 ms 23836 KB Output is correct
8 Correct 13 ms 23756 KB Output is correct
9 Correct 14 ms 24128 KB Output is correct
10 Correct 15 ms 24152 KB Output is correct
11 Correct 15 ms 24140 KB Output is correct
12 Correct 15 ms 24076 KB Output is correct
13 Correct 15 ms 24076 KB Output is correct
14 Correct 15 ms 24120 KB Output is correct
15 Correct 15 ms 24012 KB Output is correct
16 Correct 15 ms 24012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 695 ms 70124 KB Output is correct
2 Correct 703 ms 69576 KB Output is correct
3 Correct 705 ms 69896 KB Output is correct
4 Correct 697 ms 69988 KB Output is correct
5 Correct 703 ms 70284 KB Output is correct
6 Correct 743 ms 71276 KB Output is correct
7 Correct 761 ms 70900 KB Output is correct
8 Correct 723 ms 71516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 704 ms 71704 KB Output is correct
2 Correct 721 ms 70656 KB Output is correct
3 Correct 692 ms 68992 KB Output is correct
4 Correct 717 ms 70996 KB Output is correct
5 Correct 696 ms 70756 KB Output is correct
6 Correct 701 ms 71540 KB Output is correct
7 Correct 724 ms 70764 KB Output is correct
8 Correct 748 ms 71032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 536 ms 65556 KB Output is correct
2 Correct 295 ms 69108 KB Output is correct
3 Correct 279 ms 61376 KB Output is correct
4 Correct 267 ms 60456 KB Output is correct
5 Correct 254 ms 59976 KB Output is correct
6 Correct 268 ms 61268 KB Output is correct
7 Correct 256 ms 59584 KB Output is correct
8 Correct 256 ms 60092 KB Output is correct
9 Correct 253 ms 59064 KB Output is correct
10 Correct 272 ms 62268 KB Output is correct
11 Correct 263 ms 59836 KB Output is correct
12 Correct 622 ms 66508 KB Output is correct
13 Correct 275 ms 60092 KB Output is correct
14 Correct 251 ms 81816 KB Output is correct
15 Correct 187 ms 71476 KB Output is correct
16 Correct 514 ms 65544 KB Output is correct
17 Correct 551 ms 65664 KB Output is correct
18 Correct 453 ms 63888 KB Output is correct
19 Correct 305 ms 69476 KB Output is correct
20 Correct 297 ms 69492 KB Output is correct
21 Correct 309 ms 69364 KB Output is correct
22 Correct 312 ms 69316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 536 ms 65556 KB Output is correct
2 Correct 295 ms 69108 KB Output is correct
3 Correct 279 ms 61376 KB Output is correct
4 Correct 267 ms 60456 KB Output is correct
5 Correct 254 ms 59976 KB Output is correct
6 Correct 268 ms 61268 KB Output is correct
7 Correct 256 ms 59584 KB Output is correct
8 Correct 256 ms 60092 KB Output is correct
9 Correct 253 ms 59064 KB Output is correct
10 Correct 272 ms 62268 KB Output is correct
11 Correct 263 ms 59836 KB Output is correct
12 Correct 622 ms 66508 KB Output is correct
13 Correct 275 ms 60092 KB Output is correct
14 Correct 251 ms 81816 KB Output is correct
15 Correct 187 ms 71476 KB Output is correct
16 Correct 514 ms 65544 KB Output is correct
17 Correct 551 ms 65664 KB Output is correct
18 Correct 453 ms 63888 KB Output is correct
19 Correct 305 ms 69476 KB Output is correct
20 Correct 297 ms 69492 KB Output is correct
21 Correct 309 ms 69364 KB Output is correct
22 Correct 312 ms 69316 KB Output is correct
23 Correct 714 ms 66828 KB Output is correct
24 Correct 359 ms 69524 KB Output is correct
25 Correct 374 ms 60444 KB Output is correct
26 Correct 372 ms 60068 KB Output is correct
27 Correct 363 ms 59784 KB Output is correct
28 Correct 421 ms 61536 KB Output is correct
29 Correct 454 ms 60300 KB Output is correct
30 Correct 368 ms 60896 KB Output is correct
31 Correct 455 ms 61452 KB Output is correct
32 Correct 384 ms 59304 KB Output is correct
33 Correct 450 ms 60876 KB Output is correct
34 Correct 677 ms 66828 KB Output is correct
35 Correct 426 ms 59968 KB Output is correct
36 Correct 293 ms 84836 KB Output is correct
37 Correct 308 ms 84808 KB Output is correct
38 Correct 680 ms 66276 KB Output is correct
39 Correct 714 ms 65984 KB Output is correct
40 Correct 765 ms 66968 KB Output is correct
41 Correct 359 ms 69444 KB Output is correct
42 Correct 357 ms 69444 KB Output is correct
43 Correct 359 ms 69492 KB Output is correct
44 Correct 357 ms 69460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 13 ms 23884 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 13 ms 23876 KB Output is correct
7 Correct 13 ms 23836 KB Output is correct
8 Correct 13 ms 23756 KB Output is correct
9 Correct 14 ms 24128 KB Output is correct
10 Correct 15 ms 24152 KB Output is correct
11 Correct 15 ms 24140 KB Output is correct
12 Correct 15 ms 24076 KB Output is correct
13 Correct 15 ms 24076 KB Output is correct
14 Correct 15 ms 24120 KB Output is correct
15 Correct 15 ms 24012 KB Output is correct
16 Correct 15 ms 24012 KB Output is correct
17 Correct 695 ms 70124 KB Output is correct
18 Correct 703 ms 69576 KB Output is correct
19 Correct 705 ms 69896 KB Output is correct
20 Correct 697 ms 69988 KB Output is correct
21 Correct 703 ms 70284 KB Output is correct
22 Correct 743 ms 71276 KB Output is correct
23 Correct 761 ms 70900 KB Output is correct
24 Correct 723 ms 71516 KB Output is correct
25 Correct 704 ms 71704 KB Output is correct
26 Correct 721 ms 70656 KB Output is correct
27 Correct 692 ms 68992 KB Output is correct
28 Correct 717 ms 70996 KB Output is correct
29 Correct 696 ms 70756 KB Output is correct
30 Correct 701 ms 71540 KB Output is correct
31 Correct 724 ms 70764 KB Output is correct
32 Correct 748 ms 71032 KB Output is correct
33 Correct 536 ms 65556 KB Output is correct
34 Correct 295 ms 69108 KB Output is correct
35 Correct 279 ms 61376 KB Output is correct
36 Correct 267 ms 60456 KB Output is correct
37 Correct 254 ms 59976 KB Output is correct
38 Correct 268 ms 61268 KB Output is correct
39 Correct 256 ms 59584 KB Output is correct
40 Correct 256 ms 60092 KB Output is correct
41 Correct 253 ms 59064 KB Output is correct
42 Correct 272 ms 62268 KB Output is correct
43 Correct 263 ms 59836 KB Output is correct
44 Correct 622 ms 66508 KB Output is correct
45 Correct 275 ms 60092 KB Output is correct
46 Correct 251 ms 81816 KB Output is correct
47 Correct 187 ms 71476 KB Output is correct
48 Correct 514 ms 65544 KB Output is correct
49 Correct 551 ms 65664 KB Output is correct
50 Correct 453 ms 63888 KB Output is correct
51 Correct 305 ms 69476 KB Output is correct
52 Correct 297 ms 69492 KB Output is correct
53 Correct 309 ms 69364 KB Output is correct
54 Correct 312 ms 69316 KB Output is correct
55 Correct 714 ms 66828 KB Output is correct
56 Correct 359 ms 69524 KB Output is correct
57 Correct 374 ms 60444 KB Output is correct
58 Correct 372 ms 60068 KB Output is correct
59 Correct 363 ms 59784 KB Output is correct
60 Correct 421 ms 61536 KB Output is correct
61 Correct 454 ms 60300 KB Output is correct
62 Correct 368 ms 60896 KB Output is correct
63 Correct 455 ms 61452 KB Output is correct
64 Correct 384 ms 59304 KB Output is correct
65 Correct 450 ms 60876 KB Output is correct
66 Correct 677 ms 66828 KB Output is correct
67 Correct 426 ms 59968 KB Output is correct
68 Correct 293 ms 84836 KB Output is correct
69 Correct 308 ms 84808 KB Output is correct
70 Correct 680 ms 66276 KB Output is correct
71 Correct 714 ms 65984 KB Output is correct
72 Correct 765 ms 66968 KB Output is correct
73 Correct 359 ms 69444 KB Output is correct
74 Correct 357 ms 69444 KB Output is correct
75 Correct 359 ms 69492 KB Output is correct
76 Correct 357 ms 69460 KB Output is correct
77 Correct 818 ms 67448 KB Output is correct
78 Correct 362 ms 69464 KB Output is correct
79 Correct 454 ms 60716 KB Output is correct
80 Correct 453 ms 59460 KB Output is correct
81 Correct 435 ms 60724 KB Output is correct
82 Correct 481 ms 60424 KB Output is correct
83 Correct 450 ms 59740 KB Output is correct
84 Correct 456 ms 60000 KB Output is correct
85 Correct 426 ms 60984 KB Output is correct
86 Correct 433 ms 60640 KB Output is correct
87 Correct 430 ms 59964 KB Output is correct
88 Correct 615 ms 66324 KB Output is correct
89 Correct 458 ms 60468 KB Output is correct
90 Correct 296 ms 84828 KB Output is correct
91 Correct 350 ms 84824 KB Output is correct
92 Runtime error 812 ms 136088 KB Execution killed with signal 6
93 Halted 0 ms 0 KB -