Submission #575601

# Submission time Handle Problem Language Result Execution time Memory
575601 2022-06-11T06:36:38 Z Belgutei Dreaming (IOI13_dreaming) C++17
0 / 100
62 ms 17056 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define MOD 1000000007
#define MOD1 1000000009
#define sqr(x) sqr((x)*(x))

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#ifdef BE_DEBUG
#define debug(...) cerr << "\033[1;31m(" << #__VA_ARGS__ << "):\033[0m", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

const int BB = 100005;

int par[BB];
vector<pair<int,int> > edge[BB];
bool visited[BB];
vector<int> v;
int a[BB],b[BB]; // 
int tmp;
multiset<int> s;
multiset<int> :: iterator it;

vector<int> gold;
int mn;

void dfs(int node) {
    //cout << node << ' ';
    visited[node] = 1;
    v.pb(node);
    for(auto x: edge[node]) {
        if(visited[x.ff] == 1) continue;
        a[x.ff] = x.ss;
        dfs(x.ff);
        b[node] = max(b[node], a[x.ff]);
        if(node == tmp) {
            s.insert(-(b[x.ff] + x.ss));
        }
    }
    a[node] += b[node];
}

void go(int node, int cost) {
    visited[node] = 1;
    if(s.size() != 0) {
        it = s.begin();
        mn = min(mn, max(b[node],cost - *it));
    }
    else {
        mn = min(mn, max(b[node], cost));
    }
    for(auto x: edge[node]) {
        if(visited[x.ff] == 1) continue;
        if(tmp == node) {
            it = s.lower_bound(-a[x.ff]);
            s.erase(it);
        }
        go(x.ff, x.ss + cost);
        s.insert(-a[x.ff]);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i = 0; i < N; i ++) {
        par[i] = i;
    }
    for(int i = 0; i < M; i ++) {
        edge[A[i]].pb({B[i], T[i]});
        edge[B[i]].pb({A[i], T[i]});
    }
    for(int i = 0; i < N; i ++) {
        if(visited[i] == 1) continue;
        s.clear();
        tmp = i;
        v.clear();
        dfs(i);for(auto x: v) {
            visited[x] = 0;
        }
        mn = 1e9;
        go(i,0);
        gold.pb(mn);
    }
    sort(gold.begin(), gold.end());
    reverse(gold.begin(), gold.end());
    
    if(gold.size() == 1) {
        return gold[0];
    }
    if(gold.size() == 2) {
        return gold[0] + gold[1] + L;
    }
    return max(gold[0] + gold[1] + L, gold[1] + gold[3] + L + L);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 17056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 17056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 6488 KB Output is correct
2 Incorrect 23 ms 6516 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 17056 KB Output isn't correct
2 Halted 0 ms 0 KB -