답안 #404920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404920 2021-05-15T10:04:03 Z Theo830 꿈 (IOI13_dreaming) C++17
18 / 100
74 ms 11776 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 11696 KB Output is correct
2 Correct 66 ms 11776 KB Output is correct
3 Correct 38 ms 7736 KB Output is correct
4 Correct 8 ms 1996 KB Output is correct
5 Correct 7 ms 1228 KB Output is correct
6 Correct 15 ms 2844 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 11696 KB Output is correct
2 Correct 66 ms 11776 KB Output is correct
3 Correct 38 ms 7736 KB Output is correct
4 Correct 8 ms 1996 KB Output is correct
5 Correct 7 ms 1228 KB Output is correct
6 Correct 15 ms 2844 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 6292 KB Output is correct
2 Correct 32 ms 6220 KB Output is correct
3 Correct 30 ms 6260 KB Output is correct
4 Correct 30 ms 6180 KB Output is correct
5 Correct 30 ms 6152 KB Output is correct
6 Correct 32 ms 6576 KB Output is correct
7 Correct 34 ms 6536 KB Output is correct
8 Correct 30 ms 6088 KB Output is correct
9 Correct 33 ms 6004 KB Output is correct
10 Correct 34 ms 6364 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 12 ms 4344 KB Output is correct
13 Correct 11 ms 4348 KB Output is correct
14 Correct 12 ms 4264 KB Output is correct
15 Correct 11 ms 4300 KB Output is correct
16 Correct 11 ms 4296 KB Output is correct
17 Correct 11 ms 4300 KB Output is correct
18 Correct 11 ms 4292 KB Output is correct
19 Correct 11 ms 4300 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 4252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 11696 KB Output is correct
2 Correct 66 ms 11776 KB Output is correct
3 Correct 38 ms 7736 KB Output is correct
4 Correct 8 ms 1996 KB Output is correct
5 Correct 7 ms 1228 KB Output is correct
6 Correct 15 ms 2844 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -