Submission #284942

# Submission time Handle Problem Language Result Execution time Memory
284942 2020-08-28T08:18:09 Z 3zp Aesthetic (NOI20_aesthetic) C++14
51 / 100
846 ms 77276 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 500009;
vector<pair<ll, pair<ll, ll > > > v[N];
vector<ll> T[N];
ll d1[N],dn[N], f[N], g[N],ea[N],eb[N],ec[N], par[N],path[N],wh[N];
multiset<pair<ll,ll> > S;
/*
00000111111

*/
void ad(ll x){
    if(g[x] == 1)cout<<1/0;
    g[x] = 1;
    for(auto E : v[x]){
        ll y = E.first, l = E.second.first,  u= E.second.second;
        auto it= S.find({dn[y] + l + d1[x], u});
        if(g[y] == 1 && it != S.end()) S.erase(it);
        if(g[y] == 0) S.insert({dn[x] + l + d1[y], u});
    }
}
ll A = 0;
main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, m;
    cin >> n >> m;
    for(ll i = 0; i < m; i++){
        cin>>ea[i]>>eb[i]>>ec[i];
    }
    for(ll i = m-1; i >= 0; i--){
        ll a = ea[i], b = eb[i], c = ec[i];

        v[a].push_back({b, {c,A}});
        v[b].push_back({a, {c,A}});
        A = max(A, c);
    }
    for(ll i = 1; i <= n; i++){
        d1[i] = 1e18;
        dn[i] = 1e18;
    }
    d1[1] = 0;
    dn[n] = 0;
    priority_queue<pair<ll, ll> > q;
    q.push({0, 1});
    while(q.size()){
        ll x = q.top().second;
        q.pop();
        if(f[x]) continue;
        f[x] = 1;
        for(auto E: v[x]){
            ll y = E.first, l = E.second.first;
            if(!f[y] && d1[y] > d1[x] + l){
                d1[y] = d1[x] + l;
                par[y] = x;
                q.push({-d1[y], y});
            }
        }
    }
    q.push({0, n});
    for(ll i = 1; i <= n; i++)
        f[i] = 0;
    while(q.size()){
        ll x = q.top().second;
        q.pop();
        if(f[x]) continue;
        f[x] = 1;
        for(auto E: v[x]){
            ll y = E.first, l = E.second.first;
            if(!f[y] && dn[y] > dn[x] + l){
                dn[y] = dn[x] + l;
                q.push({-dn[y], y});
            }
        }
    }
    vector<pair<ll,ll> > W;
    ll ans = d1[n];
    ll X = n;
    while(1){
        path[X] = 1;
        if(X == 1) break;
        X = par[X];
    }

    for(ll i = 1; i <= n; i++){
        W.push_back({d1[i], i});
    }
    sort(W.begin(), W.end());
    for(ll i = 0; i < W.size(); i++){
        ll x = W[i].second;
        if(path[x]) wh[x] = x;
        else wh[x] = wh[par[x]];
        T[wh[x]].push_back(x);
    }
    ll x = n;
    while(1){
        for(ll y : T[x])
            ad(y);
        if(x == 1) break;
        x = par[x];
        if(S.size() == 0) continue;
        ll U = S.begin()->first + S.begin()->second;
        auto it = S.begin();
        it++;
        if(it != S.end()) U = min(U, it->first);
        ans = max(ans, U);
    }
    cout<<ans<<endl;
}

Compilation message

Aesthetic.cpp: In function 'void ad(long long int)':
Aesthetic.cpp:14:25: warning: division by zero [-Wdiv-by-zero]
   14 |     if(g[x] == 1)cout<<1/0;
      |                        ~^~
Aesthetic.cpp: At global scope:
Aesthetic.cpp:24:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   24 | main(){
      |      ^
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:90:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     for(ll i = 0; i < W.size(); i++){
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23936 KB Output is correct
2 Correct 22 ms 23936 KB Output is correct
3 Correct 16 ms 23936 KB Output is correct
4 Correct 17 ms 23936 KB Output is correct
5 Correct 16 ms 23936 KB Output is correct
6 Correct 18 ms 23936 KB Output is correct
7 Correct 16 ms 23936 KB Output is correct
8 Correct 17 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23936 KB Output is correct
2 Correct 22 ms 23936 KB Output is correct
3 Correct 16 ms 23936 KB Output is correct
4 Correct 17 ms 23936 KB Output is correct
5 Correct 16 ms 23936 KB Output is correct
6 Correct 18 ms 23936 KB Output is correct
7 Correct 16 ms 23936 KB Output is correct
8 Correct 17 ms 23936 KB Output is correct
9 Correct 18 ms 24192 KB Output is correct
10 Correct 27 ms 24192 KB Output is correct
11 Correct 21 ms 24192 KB Output is correct
12 Correct 21 ms 24192 KB Output is correct
13 Correct 17 ms 24192 KB Output is correct
14 Correct 25 ms 24192 KB Output is correct
15 Correct 18 ms 24192 KB Output is correct
16 Correct 19 ms 24192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 793 ms 74960 KB Output is correct
2 Correct 805 ms 74856 KB Output is correct
3 Correct 774 ms 73572 KB Output is correct
4 Correct 774 ms 75132 KB Output is correct
5 Correct 793 ms 73720 KB Output is correct
6 Correct 791 ms 76328 KB Output is correct
7 Correct 788 ms 75904 KB Output is correct
8 Correct 778 ms 75316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 771 ms 75132 KB Output is correct
2 Correct 789 ms 75780 KB Output is correct
3 Correct 813 ms 74336 KB Output is correct
4 Correct 785 ms 76980 KB Output is correct
5 Correct 781 ms 75764 KB Output is correct
6 Correct 756 ms 77264 KB Output is correct
7 Correct 780 ms 75856 KB Output is correct
8 Correct 770 ms 75088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 823 ms 70496 KB Output is correct
2 Correct 299 ms 70748 KB Output is correct
3 Correct 402 ms 63240 KB Output is correct
4 Correct 387 ms 62056 KB Output is correct
5 Correct 389 ms 61668 KB Output is correct
6 Correct 406 ms 63076 KB Output is correct
7 Correct 365 ms 61288 KB Output is correct
8 Correct 374 ms 61924 KB Output is correct
9 Correct 398 ms 61068 KB Output is correct
10 Correct 397 ms 64100 KB Output is correct
11 Correct 381 ms 61544 KB Output is correct
12 Correct 830 ms 70632 KB Output is correct
13 Correct 382 ms 61800 KB Output is correct
14 Correct 279 ms 77276 KB Output is correct
15 Correct 202 ms 70220 KB Output is correct
16 Correct 846 ms 71648 KB Output is correct
17 Correct 799 ms 69184 KB Output is correct
18 Correct 762 ms 71016 KB Output is correct
19 Correct 296 ms 70880 KB Output is correct
20 Correct 291 ms 70876 KB Output is correct
21 Correct 294 ms 71004 KB Output is correct
22 Correct 294 ms 70876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 823 ms 70496 KB Output is correct
2 Correct 299 ms 70748 KB Output is correct
3 Correct 402 ms 63240 KB Output is correct
4 Correct 387 ms 62056 KB Output is correct
5 Correct 389 ms 61668 KB Output is correct
6 Correct 406 ms 63076 KB Output is correct
7 Correct 365 ms 61288 KB Output is correct
8 Correct 374 ms 61924 KB Output is correct
9 Correct 398 ms 61068 KB Output is correct
10 Correct 397 ms 64100 KB Output is correct
11 Correct 381 ms 61544 KB Output is correct
12 Correct 830 ms 70632 KB Output is correct
13 Correct 382 ms 61800 KB Output is correct
14 Correct 279 ms 77276 KB Output is correct
15 Correct 202 ms 70220 KB Output is correct
16 Correct 846 ms 71648 KB Output is correct
17 Correct 799 ms 69184 KB Output is correct
18 Correct 762 ms 71016 KB Output is correct
19 Correct 296 ms 70880 KB Output is correct
20 Correct 291 ms 70876 KB Output is correct
21 Correct 294 ms 71004 KB Output is correct
22 Correct 294 ms 70876 KB Output is correct
23 Incorrect 619 ms 69084 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23936 KB Output is correct
2 Correct 22 ms 23936 KB Output is correct
3 Correct 16 ms 23936 KB Output is correct
4 Correct 17 ms 23936 KB Output is correct
5 Correct 16 ms 23936 KB Output is correct
6 Correct 18 ms 23936 KB Output is correct
7 Correct 16 ms 23936 KB Output is correct
8 Correct 17 ms 23936 KB Output is correct
9 Correct 18 ms 24192 KB Output is correct
10 Correct 27 ms 24192 KB Output is correct
11 Correct 21 ms 24192 KB Output is correct
12 Correct 21 ms 24192 KB Output is correct
13 Correct 17 ms 24192 KB Output is correct
14 Correct 25 ms 24192 KB Output is correct
15 Correct 18 ms 24192 KB Output is correct
16 Correct 19 ms 24192 KB Output is correct
17 Correct 793 ms 74960 KB Output is correct
18 Correct 805 ms 74856 KB Output is correct
19 Correct 774 ms 73572 KB Output is correct
20 Correct 774 ms 75132 KB Output is correct
21 Correct 793 ms 73720 KB Output is correct
22 Correct 791 ms 76328 KB Output is correct
23 Correct 788 ms 75904 KB Output is correct
24 Correct 778 ms 75316 KB Output is correct
25 Correct 771 ms 75132 KB Output is correct
26 Correct 789 ms 75780 KB Output is correct
27 Correct 813 ms 74336 KB Output is correct
28 Correct 785 ms 76980 KB Output is correct
29 Correct 781 ms 75764 KB Output is correct
30 Correct 756 ms 77264 KB Output is correct
31 Correct 780 ms 75856 KB Output is correct
32 Correct 770 ms 75088 KB Output is correct
33 Correct 823 ms 70496 KB Output is correct
34 Correct 299 ms 70748 KB Output is correct
35 Correct 402 ms 63240 KB Output is correct
36 Correct 387 ms 62056 KB Output is correct
37 Correct 389 ms 61668 KB Output is correct
38 Correct 406 ms 63076 KB Output is correct
39 Correct 365 ms 61288 KB Output is correct
40 Correct 374 ms 61924 KB Output is correct
41 Correct 398 ms 61068 KB Output is correct
42 Correct 397 ms 64100 KB Output is correct
43 Correct 381 ms 61544 KB Output is correct
44 Correct 830 ms 70632 KB Output is correct
45 Correct 382 ms 61800 KB Output is correct
46 Correct 279 ms 77276 KB Output is correct
47 Correct 202 ms 70220 KB Output is correct
48 Correct 846 ms 71648 KB Output is correct
49 Correct 799 ms 69184 KB Output is correct
50 Correct 762 ms 71016 KB Output is correct
51 Correct 296 ms 70880 KB Output is correct
52 Correct 291 ms 70876 KB Output is correct
53 Correct 294 ms 71004 KB Output is correct
54 Correct 294 ms 70876 KB Output is correct
55 Incorrect 619 ms 69084 KB Output isn't correct
56 Halted 0 ms 0 KB -