답안 #947927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947927 2024-03-17T09:26:03 Z steveonalex 꿈 (IOI13_dreaming) C++11
0 / 100
33 ms 13476 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 1e5 + 69;
vector<pair<int, int>> graph[N];
ll dp[N];
bool visited[N];

void go(int u, int p){
    dp[u] = 0;
    visited[u] = true;
    for(auto v: graph[u]) if (v.first != p){
        go(v.first, u);
        maximize(dp[u], dp[v.first] + v.second);
    }
}

void dfs(int u, int p, ll &ans){
    minimize(ans, dp[u]);
    pair<ll, ll> ma = {0, 0};
    for(auto v: graph[u]) {
        ll val = dp[v.first] + v.second;
        if (val > ma.first){
            ma.second = ma.first;
            ma.first = val;
        }
        else maximize(ma.second, val);
    }
    for(auto v: graph[u]) if (v.first != p){
        ll x = dp[u], y = dp[v.first];
        if (dp[v.first] + v.second == ma.first) dp[u] = ma.second;
        else dp[u] = ma.first;
        maximize(dp[v.first], dp[u] + v.second);
        dfs(v.first, u, ans);
        dp[u] = x; dp[v.first] = y;
    }
}

int travelTime(int n,int m,int l,int A[],int B[],int T[]){
    for(int i = 0; i<n; ++i){
        graph[i].clear(); visited[i] = 0; dp[i] = 0;
    }

    for(int i = 0; i<m; ++i){
        int u = A[i], v = B[i], w = T[i];
        graph[u].push_back({v, w});
        graph[v].push_back({u, w});
    }


    vector<ll> lmao;
    for(int i = 0; i<n; ++i) if (!visited[i]){
        go(i, i);
        ll cur = 1e18;
        dfs(i, i, cur);
        lmao.push_back(cur);
    }
    sort(ALL(lmao));

    if (lmao.size() > 2) exit(1);

    ll ans = lmao.back();
    if (lmao.size() >= 2) maximize(ans, lmao[lmao.size() - 2] + lmao.back() + l);
    if (lmao.size() >= 3) maximize(ans, lmao[lmao.size() - 3] + lmao[lmao.size() - 2] + 2 * l);
    return ans;
}

// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     int A[] = {0,8,2,5,5,1,1,10}, B[] = {8,2,7,11,1,3,9,6}, C[] = {4,2,4,3,7,1,5,3};
//     cout << travelTime(12, 8, 2, A,B,C) << "\n";

//     return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 13476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 13476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 6624 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 13476 KB Output isn't correct
2 Halted 0 ms 0 KB -