답안 #404915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404915 2021-05-15T09:56:02 Z Theo830 꿈 (IOI13_dreaming) C++17
18 / 100
60 ms 11736 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] = 1e9+7;
    }
    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 59 ms 11716 KB Output is correct
2 Correct 60 ms 11736 KB Output is correct
3 Correct 38 ms 7752 KB Output is correct
4 Correct 10 ms 1956 KB Output is correct
5 Correct 7 ms 1228 KB Output is correct
6 Correct 15 ms 2832 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 59 ms 11716 KB Output is correct
2 Correct 60 ms 11736 KB Output is correct
3 Correct 38 ms 7752 KB Output is correct
4 Correct 10 ms 1956 KB Output is correct
5 Correct 7 ms 1228 KB Output is correct
6 Correct 15 ms 2832 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 6156 KB Output is correct
2 Correct 32 ms 6188 KB Output is correct
3 Correct 29 ms 6148 KB Output is correct
4 Correct 32 ms 6180 KB Output is correct
5 Correct 29 ms 6140 KB Output is correct
6 Correct 37 ms 6588 KB Output is correct
7 Correct 30 ms 6424 KB Output is correct
8 Correct 32 ms 6044 KB Output is correct
9 Correct 36 ms 6104 KB Output is correct
10 Correct 36 ms 6468 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 4360 KB Output is correct
14 Correct 11 ms 4300 KB Output is correct
15 Correct 11 ms 4300 KB Output is correct
16 Correct 11 ms 4332 KB Output is correct
17 Correct 11 ms 4300 KB Output is correct
18 Correct 12 ms 4300 KB Output is correct
19 Correct 14 ms 4300 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 12 ms 4464 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 59 ms 11716 KB Output is correct
2 Correct 60 ms 11736 KB Output is correct
3 Correct 38 ms 7752 KB Output is correct
4 Correct 10 ms 1956 KB Output is correct
5 Correct 7 ms 1228 KB Output is correct
6 Correct 15 ms 2832 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -