답안 #459643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
459643 2021-08-08T21:22:14 Z nickmet2004 Aesthetic (NOI20_aesthetic) C++11
73 / 100
839 ms 134628 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n , m , au[300005] , av[300005] , aw[300005];
ll u , v , w , A;
vector<pair<ll, pair<ll , ll> > >  adj[300005];
ll d1[300005] , dn[300005] , f[300005] , par[300005] , path[300005] , son[300005];
multiset<pair<ll , ll>> S;
vector<ll> B[300005] , T[300005];
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]==1) S.erase(it);
        if(f[y.first] == 0) 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;
    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<<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 14 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 21440 KB Output is correct
5 Correct 12 ms 21452 KB Output is correct
6 Correct 12 ms 21464 KB Output is correct
7 Correct 12 ms 21452 KB Output is correct
8 Correct 12 ms 21452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 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 21440 KB Output is correct
5 Correct 12 ms 21452 KB Output is correct
6 Correct 12 ms 21464 KB Output is correct
7 Correct 12 ms 21452 KB Output is correct
8 Correct 12 ms 21452 KB Output is correct
9 Correct 14 ms 21780 KB Output is correct
10 Correct 14 ms 21836 KB Output is correct
11 Correct 14 ms 21708 KB Output is correct
12 Correct 14 ms 21780 KB Output is correct
13 Correct 14 ms 21708 KB Output is correct
14 Correct 14 ms 21668 KB Output is correct
15 Correct 14 ms 21696 KB Output is correct
16 Correct 14 ms 21748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 709 ms 70176 KB Output is correct
2 Correct 716 ms 69748 KB Output is correct
3 Correct 714 ms 69932 KB Output is correct
4 Correct 712 ms 70064 KB Output is correct
5 Correct 693 ms 70212 KB Output is correct
6 Correct 764 ms 71404 KB Output is correct
7 Correct 726 ms 70832 KB Output is correct
8 Correct 743 ms 71520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 742 ms 71708 KB Output is correct
2 Correct 736 ms 70660 KB Output is correct
3 Correct 700 ms 68868 KB Output is correct
4 Correct 743 ms 70908 KB Output is correct
5 Correct 728 ms 70788 KB Output is correct
6 Correct 704 ms 71472 KB Output is correct
7 Correct 705 ms 70600 KB Output is correct
8 Correct 701 ms 70840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 555 ms 64840 KB Output is correct
2 Correct 297 ms 68976 KB Output is correct
3 Correct 297 ms 59904 KB Output is correct
4 Correct 279 ms 58680 KB Output is correct
5 Correct 260 ms 58416 KB Output is correct
6 Correct 268 ms 59712 KB Output is correct
7 Correct 254 ms 58044 KB Output is correct
8 Correct 270 ms 58556 KB Output is correct
9 Correct 246 ms 57472 KB Output is correct
10 Correct 292 ms 60748 KB Output is correct
11 Correct 286 ms 58172 KB Output is correct
12 Correct 624 ms 65968 KB Output is correct
13 Correct 263 ms 58504 KB Output is correct
14 Correct 246 ms 80956 KB Output is correct
15 Correct 185 ms 70672 KB Output is correct
16 Correct 513 ms 64664 KB Output is correct
17 Correct 566 ms 64656 KB Output is correct
18 Correct 452 ms 63004 KB Output is correct
19 Correct 298 ms 69188 KB Output is correct
20 Correct 301 ms 69220 KB Output is correct
21 Correct 300 ms 69192 KB Output is correct
22 Correct 297 ms 69024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 555 ms 64840 KB Output is correct
2 Correct 297 ms 68976 KB Output is correct
3 Correct 297 ms 59904 KB Output is correct
4 Correct 279 ms 58680 KB Output is correct
5 Correct 260 ms 58416 KB Output is correct
6 Correct 268 ms 59712 KB Output is correct
7 Correct 254 ms 58044 KB Output is correct
8 Correct 270 ms 58556 KB Output is correct
9 Correct 246 ms 57472 KB Output is correct
10 Correct 292 ms 60748 KB Output is correct
11 Correct 286 ms 58172 KB Output is correct
12 Correct 624 ms 65968 KB Output is correct
13 Correct 263 ms 58504 KB Output is correct
14 Correct 246 ms 80956 KB Output is correct
15 Correct 185 ms 70672 KB Output is correct
16 Correct 513 ms 64664 KB Output is correct
17 Correct 566 ms 64656 KB Output is correct
18 Correct 452 ms 63004 KB Output is correct
19 Correct 298 ms 69188 KB Output is correct
20 Correct 301 ms 69220 KB Output is correct
21 Correct 300 ms 69192 KB Output is correct
22 Correct 297 ms 69024 KB Output is correct
23 Correct 701 ms 66020 KB Output is correct
24 Correct 358 ms 69328 KB Output is correct
25 Correct 373 ms 59068 KB Output is correct
26 Correct 372 ms 58500 KB Output is correct
27 Correct 340 ms 58380 KB Output is correct
28 Correct 421 ms 59976 KB Output is correct
29 Correct 410 ms 58644 KB Output is correct
30 Correct 365 ms 59248 KB Output is correct
31 Correct 425 ms 59852 KB Output is correct
32 Correct 386 ms 57680 KB Output is correct
33 Correct 407 ms 59424 KB Output is correct
34 Correct 698 ms 66064 KB Output is correct
35 Correct 410 ms 58412 KB Output is correct
36 Correct 288 ms 83624 KB Output is correct
37 Correct 307 ms 83812 KB Output is correct
38 Correct 663 ms 65508 KB Output is correct
39 Correct 671 ms 65076 KB Output is correct
40 Correct 746 ms 66160 KB Output is correct
41 Correct 356 ms 69232 KB Output is correct
42 Correct 357 ms 69048 KB Output is correct
43 Correct 360 ms 69268 KB Output is correct
44 Correct 355 ms 69072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 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 21440 KB Output is correct
5 Correct 12 ms 21452 KB Output is correct
6 Correct 12 ms 21464 KB Output is correct
7 Correct 12 ms 21452 KB Output is correct
8 Correct 12 ms 21452 KB Output is correct
9 Correct 14 ms 21780 KB Output is correct
10 Correct 14 ms 21836 KB Output is correct
11 Correct 14 ms 21708 KB Output is correct
12 Correct 14 ms 21780 KB Output is correct
13 Correct 14 ms 21708 KB Output is correct
14 Correct 14 ms 21668 KB Output is correct
15 Correct 14 ms 21696 KB Output is correct
16 Correct 14 ms 21748 KB Output is correct
17 Correct 709 ms 70176 KB Output is correct
18 Correct 716 ms 69748 KB Output is correct
19 Correct 714 ms 69932 KB Output is correct
20 Correct 712 ms 70064 KB Output is correct
21 Correct 693 ms 70212 KB Output is correct
22 Correct 764 ms 71404 KB Output is correct
23 Correct 726 ms 70832 KB Output is correct
24 Correct 743 ms 71520 KB Output is correct
25 Correct 742 ms 71708 KB Output is correct
26 Correct 736 ms 70660 KB Output is correct
27 Correct 700 ms 68868 KB Output is correct
28 Correct 743 ms 70908 KB Output is correct
29 Correct 728 ms 70788 KB Output is correct
30 Correct 704 ms 71472 KB Output is correct
31 Correct 705 ms 70600 KB Output is correct
32 Correct 701 ms 70840 KB Output is correct
33 Correct 555 ms 64840 KB Output is correct
34 Correct 297 ms 68976 KB Output is correct
35 Correct 297 ms 59904 KB Output is correct
36 Correct 279 ms 58680 KB Output is correct
37 Correct 260 ms 58416 KB Output is correct
38 Correct 268 ms 59712 KB Output is correct
39 Correct 254 ms 58044 KB Output is correct
40 Correct 270 ms 58556 KB Output is correct
41 Correct 246 ms 57472 KB Output is correct
42 Correct 292 ms 60748 KB Output is correct
43 Correct 286 ms 58172 KB Output is correct
44 Correct 624 ms 65968 KB Output is correct
45 Correct 263 ms 58504 KB Output is correct
46 Correct 246 ms 80956 KB Output is correct
47 Correct 185 ms 70672 KB Output is correct
48 Correct 513 ms 64664 KB Output is correct
49 Correct 566 ms 64656 KB Output is correct
50 Correct 452 ms 63004 KB Output is correct
51 Correct 298 ms 69188 KB Output is correct
52 Correct 301 ms 69220 KB Output is correct
53 Correct 300 ms 69192 KB Output is correct
54 Correct 297 ms 69024 KB Output is correct
55 Correct 701 ms 66020 KB Output is correct
56 Correct 358 ms 69328 KB Output is correct
57 Correct 373 ms 59068 KB Output is correct
58 Correct 372 ms 58500 KB Output is correct
59 Correct 340 ms 58380 KB Output is correct
60 Correct 421 ms 59976 KB Output is correct
61 Correct 410 ms 58644 KB Output is correct
62 Correct 365 ms 59248 KB Output is correct
63 Correct 425 ms 59852 KB Output is correct
64 Correct 386 ms 57680 KB Output is correct
65 Correct 407 ms 59424 KB Output is correct
66 Correct 698 ms 66064 KB Output is correct
67 Correct 410 ms 58412 KB Output is correct
68 Correct 288 ms 83624 KB Output is correct
69 Correct 307 ms 83812 KB Output is correct
70 Correct 663 ms 65508 KB Output is correct
71 Correct 671 ms 65076 KB Output is correct
72 Correct 746 ms 66160 KB Output is correct
73 Correct 356 ms 69232 KB Output is correct
74 Correct 357 ms 69048 KB Output is correct
75 Correct 360 ms 69268 KB Output is correct
76 Correct 355 ms 69072 KB Output is correct
77 Correct 805 ms 66732 KB Output is correct
78 Correct 365 ms 69316 KB Output is correct
79 Correct 429 ms 59168 KB Output is correct
80 Correct 448 ms 57856 KB Output is correct
81 Correct 429 ms 59124 KB Output is correct
82 Correct 478 ms 58912 KB Output is correct
83 Correct 442 ms 58304 KB Output is correct
84 Correct 457 ms 58484 KB Output is correct
85 Correct 411 ms 59556 KB Output is correct
86 Correct 431 ms 59176 KB Output is correct
87 Correct 427 ms 58300 KB Output is correct
88 Correct 611 ms 65636 KB Output is correct
89 Correct 443 ms 58932 KB Output is correct
90 Correct 325 ms 83684 KB Output is correct
91 Correct 360 ms 83720 KB Output is correct
92 Runtime error 839 ms 134628 KB Execution killed with signal 6
93 Halted 0 ms 0 KB -