Submission #459621

# Submission time Handle Problem Language Result Execution time Memory
459621 2021-08-08T20:52:17 Z nickmet2004 Aesthetic (NOI20_aesthetic) C++11
0 / 100
2000 ms 36956 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 5;
int n , m , au[N] , av[N] , aw[N];
int u , v , w , A;
vector<pair<int, pair<int , int> > >  adj[N];
ll d1[N] , dn[N] , f[N] , par[N] , path[N] , son[N];
priority_queue<pair<ll , ll> > pq;
multiset<pair<ll , int>> 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);
    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;
    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;
    u = n;
    ll ans = d1[n];
    //cout << "ka";
    ll k;
    while(1){
        //cout << "ha";
        if(u == 1)break;
        for(ll v : T[u]) q(v);
        u = par[u];
        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:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main (){
      | ^~~~
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:29:15: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
   29 |     scanf("%lld%lld" , &n , &m);
      |            ~~~^        ~~
      |               |        |
      |               |        int*
      |               long long int*
      |            %d
Aesthetic.cpp:29:19: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'int*' [-Wformat=]
   29 |     scanf("%lld%lld" , &n , &m);
      |                ~~~^         ~~
      |                   |         |
      |                   |         int*
      |                   long long int*
      |                %d
Aesthetic.cpp:30:41: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
   30 |     for(int i  =0; i <m; ++i) scanf("%lld%lld%lld" , &au[i] , &av[i], &aw[i]);
      |                                      ~~~^            ~~~~~~
      |                                         |            |
      |                                         |            int*
      |                                         long long int*
      |                                      %d
Aesthetic.cpp:30:45: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'int*' [-Wformat=]
   30 |     for(int i  =0; i <m; ++i) scanf("%lld%lld%lld" , &au[i] , &av[i], &aw[i]);
      |                                          ~~~^                 ~~~~~~
      |                                             |                 |
      |                                             long long int*    int*
      |                                          %d
Aesthetic.cpp:30:49: warning: format '%lld' expects argument of type 'long long int*', but argument 4 has type 'int*' [-Wformat=]
   30 |     for(int i  =0; i <m; ++i) scanf("%lld%lld%lld" , &au[i] , &av[i], &aw[i]);
      |                                              ~~~^                     ~~~~~~
      |                                                 |                     |
      |                                                 long long int*        int*
      |                                              %d
Aesthetic.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%lld%lld" , &n , &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Aesthetic.cpp:30:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     for(int i  =0; i <m; ++i) scanf("%lld%lld%lld" , &au[i] , &av[i], &aw[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 21452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 21452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2085 ms 36604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2068 ms 36956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 36392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 36392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 21452 KB Time limit exceeded
2 Halted 0 ms 0 KB -