Submission #404918

# Submission time Handle Problem Language Result Execution time Memory
404918 2021-05-15T10:01:56 Z Theo830 Dreaming (IOI13_dreaming) C++17
18 / 100
64 ms 11772 KB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef unsigned long long ull;
ll INF = INT_MAX;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "dreaming.h"
int res = 0;
vector<ll>dist[2];
ll subtree[100005];
ll pos = 0;
vector<vector<ii> >adj;
ll maxi = 0;
ll node;
bool v[100005] = {0};
priority_queue<ii,vector<ii>,greater<ii> > pq;
void dfs(ll s,ll p,ll sum){
    maxi = max(maxi,sum);
    v[s] = 1;
    subtree[s] = pos;
    if(sum == maxi){
        node = s;
    }
    for(auto x:adj[s]){
        if(x.F != p){
            dfs(x.F,s,sum+x.S);
        }
    }
}
void dijkstra(ll s,ll pos){
    dist[pos][s] = 0;
    pq.push(ii(0,s));
    while(!pq.empty()){
        ii f = pq.top();
        pq.pop();
        ll w,u;
        w = f.F;
        u = f.S;
        if(w > dist[pos][u]){
            continue;
        }
        for(auto x:adj[u]){
            if(dist[pos][u] + 1 < dist[pos][x.F]){
                dist[pos][x.F] = dist[pos][u] + x.S;
                pq.push(ii(dist[pos][x.F],x.F));
            }
        }
    }
}
int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
    adj.assign(n+5,vector<ii>());
    f(i,0,m){
        adj[A[i]].pb(ii(B[i],T[i]));
        adj[B[i]].pb(ii(A[i],T[i]));
    }
    dist[0].assign(n+5,INF);
    dist[1].assign(n+5,INF);
    f(i,1,n+1){
        if(v[i] == 0){
            maxi = 0;
            dfs(i,0,0);
            ll u = node;
            maxi = 0;
            dfs(u,0,0);
            dijkstra(u,0);
            dijkstra(node,1);
            pos++;
        }
    }
    ll mini[pos];
    f(i,0,pos){
        mini[i] = INF;
    }
    f(i,1,n+1){
        res = max({res,dist[0][i],dist[1][i]});
        mini[subtree[i]] = min(mini[subtree[i]],max(dist[0][i],dist[1][i]));
    }
    sort(mini,mini+pos);
    if(pos >= 2){
        res = max(res,mini[pos-1] + mini[pos-2] + L);
    }
    if(pos >= 3){
        res = max(res,mini[pos-3] + mini[pos-2] + 2 * L);
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 63 ms 11772 KB Output is correct
2 Correct 64 ms 11752 KB Output is correct
3 Correct 41 ms 7736 KB Output is correct
4 Correct 9 ms 1936 KB Output is correct
5 Correct 8 ms 1348 KB Output is correct
6 Correct 15 ms 2764 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 11772 KB Output is correct
2 Correct 64 ms 11752 KB Output is correct
3 Correct 41 ms 7736 KB Output is correct
4 Correct 9 ms 1936 KB Output is correct
5 Correct 8 ms 1348 KB Output is correct
6 Correct 15 ms 2764 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 6180 KB Output is correct
2 Correct 39 ms 6288 KB Output is correct
3 Correct 34 ms 6212 KB Output is correct
4 Correct 36 ms 6180 KB Output is correct
5 Correct 40 ms 6212 KB Output is correct
6 Correct 34 ms 6584 KB Output is correct
7 Correct 34 ms 6428 KB Output is correct
8 Correct 29 ms 6124 KB Output is correct
9 Correct 31 ms 6092 KB Output is correct
10 Correct 34 ms 6480 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 4336 KB Output is correct
13 Correct 11 ms 4356 KB Output is correct
14 Correct 12 ms 4316 KB Output is correct
15 Correct 11 ms 4340 KB Output is correct
16 Correct 11 ms 4300 KB Output is correct
17 Correct 13 ms 4324 KB Output is correct
18 Correct 12 ms 4364 KB Output is correct
19 Correct 11 ms 4324 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 11 ms 4300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 11772 KB Output is correct
2 Correct 64 ms 11752 KB Output is correct
3 Correct 41 ms 7736 KB Output is correct
4 Correct 9 ms 1936 KB Output is correct
5 Correct 8 ms 1348 KB Output is correct
6 Correct 15 ms 2764 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -