Submission #404846

# Submission time Handle Problem Language Result Execution time Memory
404846 2021-05-15T06:55:46 Z danielcm585 Dreaming (IOI13_dreaming) C++14
0 / 100
45 ms 10180 KB
#include "dreaming.h"

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

typedef pair<int,int> ii;

vector<int> sz, dep;
vector<vector<ii>> adj;

void dfs(int cur, int par) {
    sz[cur] = 1;
    for (auto nx : adj[cur]) {
        if (nx.fi == par) continue;
        dfs(nx.fi,cur);
        sz[cur] += sz[nx.fi];
    }
}

int maxDist(int cur, int par) {
    int ret = dep[cur];
    for (auto nx : adj[cur]) {
        if (nx.fi == par) continue;
        dep[nx.fi] = dep[cur]+nx.se;
        ret = max(ret,maxDist(nx.fi,cur));
    }
    return ret;
}

int centroid(int cur, int par, int sub) {
    for (auto nx : adj[cur]) {
        if (nx.fi == par) continue;
        if (sz[nx.fi]*2 >= sub) return centroid(nx.fi,cur,sub);
    }
    return cur;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    adj = vector<vector<ii>>(N);
    for (int i = 0; i < M; i++) {
        adj[A[i]].push_back(ii(B[i],T[i]));
        adj[B[i]].push_back(ii(A[i],T[i]));
    }
    sz = dep = vector<int>(N,0);
    vector<int> tmp;
    for (int i = 0; i < N; i++) {
        if (!sz[i]) {
            dfs(i,-1);
            int cent = centroid(i,-1,sz[i]);
            int maxi = maxDist(cent,-1);
            tmp.push_back(maxi);
        }
    }
    sort(tmp.rbegin(),tmp.rend());
    if (tmp.size() == 1) return tmp[0];
    return tmp[0]+tmp[1]+L;
    // sort(tmp.begin(),tmp.end());
    // N = tmp.size();
    // vector<int> v(N);
    // for (int i = 0, l = (N-1)/2, r = (N-1)/2+1; i < N; i++) {
    //     if (i&1) v[r++] = tmp.back();
    //     else v[l--] = tmp.back();
    //     tmp.pop_back();
    // }
    // int ans = 0;
    // priority_queue<int> pq;
    // for (int i = 0; i < N; i++) {
    //     if (!pq.empty()) ans = max(ans,v[i]+i*L+pq.top());
    //     pq.push(v[i]-i*L);
    // }
    // return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 10180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 10180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 5952 KB Output is correct
2 Incorrect 22 ms 6340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 10180 KB Output isn't correct
2 Halted 0 ms 0 KB -