답안 #459630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
459630 2021-08-08T21:04:06 Z nickmet2004 Aesthetic (NOI20_aesthetic) C++11
73 / 100
901 ms 134784 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 10;
ll n , m , au[N] , av[N] , aw[N];
ll u , v , w , A;
vector<pair<ll, pair<ll , ll> > >  adj[N];
ll d1[N] , dn[N] , f[N] , par[N] , path[N] , son[N];
multiset<pair<ll , ll>> S;
vector<ll> B[N] , T[N];
void q(ll 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);
    scanf("%lld%lld" , &n , &m);
    for(int i  =0; i <m; ++i) scanf("%lld%lld%lld" , &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;
    priority_queue<pair<ll , ll> > pq;
    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";
    }
    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();
        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);

    for(int i = 1; i <= n; ++i) f[i] =0;
    ll s = n;
    ll ans = d1[n];
    //cout << "ka";
    ll k;
    while(1){
        //cout << "ha";
        if(s == 1)break;
        for(ll v : T[s]) q(v);
        s = par[s];
        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;
    printf("%lld" ,ans);
}

Compilation message

Aesthetic.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main (){
      | ^~~~
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%lld%lld" , &n , &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Aesthetic.cpp:29:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     for(int i  =0; i <m; ++i) scanf("%lld%lld%lld" , &au[i] , &av[i], &aw[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 21452 KB Output is correct
2 Correct 13 ms 21460 KB Output is correct
3 Correct 12 ms 21540 KB Output is correct
4 Correct 12 ms 21452 KB Output is correct
5 Correct 13 ms 21452 KB Output is correct
6 Correct 12 ms 21452 KB Output is correct
7 Correct 12 ms 21436 KB Output is correct
8 Correct 13 ms 21472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 21452 KB Output is correct
2 Correct 13 ms 21460 KB Output is correct
3 Correct 12 ms 21540 KB Output is correct
4 Correct 12 ms 21452 KB Output is correct
5 Correct 13 ms 21452 KB Output is correct
6 Correct 12 ms 21452 KB Output is correct
7 Correct 12 ms 21436 KB Output is correct
8 Correct 13 ms 21472 KB Output is correct
9 Correct 15 ms 21836 KB Output is correct
10 Correct 15 ms 21708 KB Output is correct
11 Correct 14 ms 21812 KB Output is correct
12 Correct 15 ms 21708 KB Output is correct
13 Correct 13 ms 21768 KB Output is correct
14 Correct 14 ms 21788 KB Output is correct
15 Correct 13 ms 21740 KB Output is correct
16 Correct 13 ms 21708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 752 ms 70104 KB Output is correct
2 Correct 761 ms 69624 KB Output is correct
3 Correct 780 ms 69648 KB Output is correct
4 Correct 766 ms 69872 KB Output is correct
5 Correct 732 ms 70304 KB Output is correct
6 Correct 745 ms 71272 KB Output is correct
7 Correct 732 ms 70764 KB Output is correct
8 Correct 735 ms 71448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 729 ms 71748 KB Output is correct
2 Correct 783 ms 70444 KB Output is correct
3 Correct 816 ms 68956 KB Output is correct
4 Correct 752 ms 70884 KB Output is correct
5 Correct 727 ms 70764 KB Output is correct
6 Correct 733 ms 71400 KB Output is correct
7 Correct 726 ms 70668 KB Output is correct
8 Correct 724 ms 70860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 582 ms 65024 KB Output is correct
2 Correct 311 ms 68820 KB Output is correct
3 Correct 289 ms 59968 KB Output is correct
4 Correct 298 ms 58728 KB Output is correct
5 Correct 261 ms 58456 KB Output is correct
6 Correct 278 ms 59712 KB Output is correct
7 Correct 258 ms 58028 KB Output is correct
8 Correct 291 ms 58588 KB Output is correct
9 Correct 254 ms 57440 KB Output is correct
10 Correct 298 ms 60636 KB Output is correct
11 Correct 279 ms 58148 KB Output is correct
12 Correct 667 ms 65704 KB Output is correct
13 Correct 269 ms 58464 KB Output is correct
14 Correct 255 ms 80956 KB Output is correct
15 Correct 188 ms 70772 KB Output is correct
16 Correct 508 ms 64696 KB Output is correct
17 Correct 598 ms 64840 KB Output is correct
18 Correct 474 ms 63048 KB Output is correct
19 Correct 304 ms 69084 KB Output is correct
20 Correct 304 ms 69008 KB Output is correct
21 Correct 302 ms 69012 KB Output is correct
22 Correct 301 ms 68912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 582 ms 65024 KB Output is correct
2 Correct 311 ms 68820 KB Output is correct
3 Correct 289 ms 59968 KB Output is correct
4 Correct 298 ms 58728 KB Output is correct
5 Correct 261 ms 58456 KB Output is correct
6 Correct 278 ms 59712 KB Output is correct
7 Correct 258 ms 58028 KB Output is correct
8 Correct 291 ms 58588 KB Output is correct
9 Correct 254 ms 57440 KB Output is correct
10 Correct 298 ms 60636 KB Output is correct
11 Correct 279 ms 58148 KB Output is correct
12 Correct 667 ms 65704 KB Output is correct
13 Correct 269 ms 58464 KB Output is correct
14 Correct 255 ms 80956 KB Output is correct
15 Correct 188 ms 70772 KB Output is correct
16 Correct 508 ms 64696 KB Output is correct
17 Correct 598 ms 64840 KB Output is correct
18 Correct 474 ms 63048 KB Output is correct
19 Correct 304 ms 69084 KB Output is correct
20 Correct 304 ms 69008 KB Output is correct
21 Correct 302 ms 69012 KB Output is correct
22 Correct 301 ms 68912 KB Output is correct
23 Correct 773 ms 66120 KB Output is correct
24 Correct 357 ms 69140 KB Output is correct
25 Correct 403 ms 58980 KB Output is correct
26 Correct 395 ms 58584 KB Output is correct
27 Correct 359 ms 58264 KB Output is correct
28 Correct 449 ms 60244 KB Output is correct
29 Correct 418 ms 58656 KB Output is correct
30 Correct 415 ms 59248 KB Output is correct
31 Correct 426 ms 59840 KB Output is correct
32 Correct 399 ms 57800 KB Output is correct
33 Correct 428 ms 59328 KB Output is correct
34 Correct 732 ms 65968 KB Output is correct
35 Correct 417 ms 58472 KB Output is correct
36 Correct 269 ms 83640 KB Output is correct
37 Correct 291 ms 83644 KB Output is correct
38 Correct 703 ms 65484 KB Output is correct
39 Correct 766 ms 65208 KB Output is correct
40 Correct 858 ms 66192 KB Output is correct
41 Correct 364 ms 69204 KB Output is correct
42 Correct 376 ms 69164 KB Output is correct
43 Correct 369 ms 69124 KB Output is correct
44 Correct 386 ms 69108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 21452 KB Output is correct
2 Correct 13 ms 21460 KB Output is correct
3 Correct 12 ms 21540 KB Output is correct
4 Correct 12 ms 21452 KB Output is correct
5 Correct 13 ms 21452 KB Output is correct
6 Correct 12 ms 21452 KB Output is correct
7 Correct 12 ms 21436 KB Output is correct
8 Correct 13 ms 21472 KB Output is correct
9 Correct 15 ms 21836 KB Output is correct
10 Correct 15 ms 21708 KB Output is correct
11 Correct 14 ms 21812 KB Output is correct
12 Correct 15 ms 21708 KB Output is correct
13 Correct 13 ms 21768 KB Output is correct
14 Correct 14 ms 21788 KB Output is correct
15 Correct 13 ms 21740 KB Output is correct
16 Correct 13 ms 21708 KB Output is correct
17 Correct 752 ms 70104 KB Output is correct
18 Correct 761 ms 69624 KB Output is correct
19 Correct 780 ms 69648 KB Output is correct
20 Correct 766 ms 69872 KB Output is correct
21 Correct 732 ms 70304 KB Output is correct
22 Correct 745 ms 71272 KB Output is correct
23 Correct 732 ms 70764 KB Output is correct
24 Correct 735 ms 71448 KB Output is correct
25 Correct 729 ms 71748 KB Output is correct
26 Correct 783 ms 70444 KB Output is correct
27 Correct 816 ms 68956 KB Output is correct
28 Correct 752 ms 70884 KB Output is correct
29 Correct 727 ms 70764 KB Output is correct
30 Correct 733 ms 71400 KB Output is correct
31 Correct 726 ms 70668 KB Output is correct
32 Correct 724 ms 70860 KB Output is correct
33 Correct 582 ms 65024 KB Output is correct
34 Correct 311 ms 68820 KB Output is correct
35 Correct 289 ms 59968 KB Output is correct
36 Correct 298 ms 58728 KB Output is correct
37 Correct 261 ms 58456 KB Output is correct
38 Correct 278 ms 59712 KB Output is correct
39 Correct 258 ms 58028 KB Output is correct
40 Correct 291 ms 58588 KB Output is correct
41 Correct 254 ms 57440 KB Output is correct
42 Correct 298 ms 60636 KB Output is correct
43 Correct 279 ms 58148 KB Output is correct
44 Correct 667 ms 65704 KB Output is correct
45 Correct 269 ms 58464 KB Output is correct
46 Correct 255 ms 80956 KB Output is correct
47 Correct 188 ms 70772 KB Output is correct
48 Correct 508 ms 64696 KB Output is correct
49 Correct 598 ms 64840 KB Output is correct
50 Correct 474 ms 63048 KB Output is correct
51 Correct 304 ms 69084 KB Output is correct
52 Correct 304 ms 69008 KB Output is correct
53 Correct 302 ms 69012 KB Output is correct
54 Correct 301 ms 68912 KB Output is correct
55 Correct 773 ms 66120 KB Output is correct
56 Correct 357 ms 69140 KB Output is correct
57 Correct 403 ms 58980 KB Output is correct
58 Correct 395 ms 58584 KB Output is correct
59 Correct 359 ms 58264 KB Output is correct
60 Correct 449 ms 60244 KB Output is correct
61 Correct 418 ms 58656 KB Output is correct
62 Correct 415 ms 59248 KB Output is correct
63 Correct 426 ms 59840 KB Output is correct
64 Correct 399 ms 57800 KB Output is correct
65 Correct 428 ms 59328 KB Output is correct
66 Correct 732 ms 65968 KB Output is correct
67 Correct 417 ms 58472 KB Output is correct
68 Correct 269 ms 83640 KB Output is correct
69 Correct 291 ms 83644 KB Output is correct
70 Correct 703 ms 65484 KB Output is correct
71 Correct 766 ms 65208 KB Output is correct
72 Correct 858 ms 66192 KB Output is correct
73 Correct 364 ms 69204 KB Output is correct
74 Correct 376 ms 69164 KB Output is correct
75 Correct 369 ms 69124 KB Output is correct
76 Correct 386 ms 69108 KB Output is correct
77 Correct 901 ms 66548 KB Output is correct
78 Correct 405 ms 69592 KB Output is correct
79 Correct 536 ms 59540 KB Output is correct
80 Correct 494 ms 58300 KB Output is correct
81 Correct 521 ms 59476 KB Output is correct
82 Correct 549 ms 59396 KB Output is correct
83 Correct 483 ms 58656 KB Output is correct
84 Correct 482 ms 58628 KB Output is correct
85 Correct 411 ms 59872 KB Output is correct
86 Correct 475 ms 59348 KB Output is correct
87 Correct 458 ms 58584 KB Output is correct
88 Correct 696 ms 66000 KB Output is correct
89 Correct 460 ms 59116 KB Output is correct
90 Correct 299 ms 83908 KB Output is correct
91 Correct 321 ms 83972 KB Output is correct
92 Runtime error 843 ms 134784 KB Execution killed with signal 6
93 Halted 0 ms 0 KB -