Submission #561467

# Submission time Handle Problem Language Result Execution time Memory
561467 2022-05-12T22:11:30 Z urosk Dreaming (IOI13_dreaming) C++14
0 / 100
46 ms 12492 KB
#include "dreaming.h"
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll int
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 100005
ll n,m,l;
vector<pll> g[maxn];
ll dp[maxn];
ll up[maxn];
pll dpmx[maxn];
bool vis[maxn];
ll dsu[maxn];
ll root(ll x){
    while(x!=dsu[x]){
        dsu[x] = dsu[dsu[x]];
        x = dsu[x];
    }
    return x;
}
void upd(ll x,ll y){
    x = root(x);
    y = root(y);
    if(dp[x]>dp[y]) dsu[x] = y;
    else dsu[y] = x;
}
void dfs(ll u,ll par){
    vis[u] = 1;
    dp[u] = 0;
    dpmx[u] = {0,0};
    for(pll p : g[u]){
        ll s = p.fi;
        ll w = p.sc;
        if(s==par) continue;
        dfs(s,u);
        dp[u] = max(dp[s]+w,dp[u]);
        if(dp[s]+w>dpmx[u].fi){
            dpmx[u].sc = dpmx[u].fi;
            dpmx[u].fi = dp[s]+w;
        }else if(dp[s]+w>dpmx[u].sc){
            dpmx[u].sc = dp[s]+w;
        }
    }
}
void dfs2(ll u,ll par,ll w){
    if(u!=par){
        up[u] = up[par]+w;
        pll p = dpmx[par];
        ll x;
        if(dp[u]+w==p.fi) x = p.sc;
        else x = p.fi;
        up[u] = max(up[u],x+w);
    }
    vis[u] = 1;
    for(pll p : g[u]){
        ll s = p.fi;
        ll w = p.sc;
        if(s==par) continue;
        dfs2(s,u,w);
    }
}
void dfs3(ll u,ll par){
    vis[u] = 1;
    for(pll p : g[u]){
        ll s = p.fi;
        ll w = p.sc;
        if(s==par) continue;
        upd(s,u);
        dfs3(s,u);
    }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n = N; m = M; l = L;
    iota(dsu+1,dsu+n+1,1);
    for(ll i = 0;i<m;i++){
        ll x = A[i];
        ll y = B[i];
        ll w = T[i];
        x++;
        y++;
        g[x].pb({y,w});
        g[y].pb({x,w});
    }
    for(ll i = 1;i<=n;i++) if(!vis[i]) dfs(i,i);
    fill(vis,vis+n+1,0);
    for(ll i = 1;i<=n;i++) if(!vis[i]) dfs2(i,i,0);
    for(ll i = 1;i<=n;i++) dp[i] = max(dp[i],up[i]);
    fill(vis,vis+n+1,0);
    for(ll i = 1;i<=n;i++) if(!vis[i]) dfs3(i,i);
    ll ans = 0;
    for(ll i = 1;i<=n;i++) ans = max(ans,dp[i]);
    fill(vis,vis+n+1,0);
    priority_queue<ll> pq;
    for(ll i = 1;i<=n;i++){
        ll x = root(i);
        if(vis[x]) continue;
        pq.push(-dp[x]);
        vis[x] = 1;
    }
    while(sz(pq)>=2){
        ll x = -pq.top();
        pq.pop();
        ll y = -pq.top();
        pq.pop();
        ll z = max(x,y)+l;
        ans = max(ans,x+y);
        pq.push(-z);
    }
    if(sz(pq)) ans = max(ans,-pq.top());
    return ans;
}

Compilation message

dreaming.cpp: In function 'void dfs3(int, int)':
dreaming.cpp:81:12: warning: unused variable 'w' [-Wunused-variable]
   81 |         ll w = p.sc;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 46 ms 12492 KB Output is correct
2 Correct 44 ms 12236 KB Output is correct
3 Correct 29 ms 10572 KB Output is correct
4 Correct 7 ms 4224 KB Output is correct
5 Correct 6 ms 3548 KB Output is correct
6 Correct 12 ms 4820 KB Output is correct
7 Incorrect 2 ms 2656 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 2 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 12492 KB Output is correct
2 Correct 44 ms 12236 KB Output is correct
3 Correct 29 ms 10572 KB Output is correct
4 Correct 7 ms 4224 KB Output is correct
5 Correct 6 ms 3548 KB Output is correct
6 Correct 12 ms 4820 KB Output is correct
7 Incorrect 2 ms 2656 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 7392 KB Output is correct
2 Incorrect 36 ms 7340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 2 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 12492 KB Output is correct
2 Correct 44 ms 12236 KB Output is correct
3 Correct 29 ms 10572 KB Output is correct
4 Correct 7 ms 4224 KB Output is correct
5 Correct 6 ms 3548 KB Output is correct
6 Correct 12 ms 4820 KB Output is correct
7 Incorrect 2 ms 2656 KB Output isn't correct
8 Halted 0 ms 0 KB -