Submission #405276

# Submission time Handle Problem Language Result Execution time Memory
405276 2021-05-16T06:58:27 Z danielcm585 Dreaming (IOI13_dreaming) C++14
18 / 100
51 ms 11464 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];
    else {
        int ans = tmp[0]+tmp[1]+L;
        if (tmp.size() >= 3) ans = max(ans,tmp[1]+tmp[2]+2*L);
        return ans;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 11464 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 51 ms 11464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 6264 KB Output is correct
2 Correct 26 ms 6348 KB Output is correct
3 Correct 26 ms 6320 KB Output is correct
4 Correct 26 ms 6292 KB Output is correct
5 Correct 24 ms 6304 KB Output is correct
6 Correct 27 ms 6972 KB Output is correct
7 Correct 26 ms 6608 KB Output is correct
8 Correct 24 ms 6220 KB Output is correct
9 Correct 26 ms 6128 KB Output is correct
10 Correct 25 ms 6548 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 6 ms 4040 KB Output is correct
13 Correct 6 ms 4040 KB Output is correct
14 Correct 7 ms 4040 KB Output is correct
15 Correct 6 ms 4040 KB Output is correct
16 Correct 8 ms 4040 KB Output is correct
17 Correct 6 ms 4040 KB Output is correct
18 Correct 6 ms 4040 KB Output is correct
19 Correct 6 ms 4040 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 412 KB Output is correct
23 Correct 6 ms 4040 KB Output is correct
# 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 51 ms 11464 KB Output isn't correct
2 Halted 0 ms 0 KB -