Submission #405296

# Submission time Handle Problem Language Result Execution time Memory
405296 2021-05-16T07:34:39 Z danielcm585 Dreaming (IOI13_dreaming) C++14
18 / 100
60 ms 12772 KB
#include "dreaming.h"

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

#define fi first
#define se second

typedef pair<int,int> ii;

int ans, far;
vector<int> dis, sz;
vector<vector<ii>> adj;

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

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+5);
    for (int i = 0; i < M; i++) {
        A[i]++, B[i]++;
        adj[A[i]].push_back(ii(B[i],T[i]));
        adj[B[i]].push_back(ii(A[i],T[i]));
    }
    dis = sz = vector<int>(N+5,0);
    vector<int> com;
    for (int i = 1; i <= N; i++) {
        if (!sz[i]) {
            // get this component's diameter
            dis[i] = 0; far = i; dfs(i,-1);
            dis[far] = 0; dfs(far,-1);
            // get this component's centroid
            dis[i] = 0; far = i; dfs(i,-1);
            int cent = centroid(i,-1,sz[i]);
            dis[cent] = 0; far = cent; dfs(cent,-1);
            com.push_back(dis[far]);
        }
    }
    sort(com.rbegin(),com.rend());
    if (com.size() >= 2) ans = max(ans,com[0]+com[1]+L);
    if (com.size() >= 3) ans = max(ans,com[1]+com[2]+2*L);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 59 ms 12772 KB Output is correct
2 Correct 60 ms 12752 KB Output is correct
3 Correct 40 ms 8500 KB Output is correct
4 Correct 8 ms 2124 KB Output is correct
5 Correct 7 ms 1372 KB Output is correct
6 Correct 14 ms 2976 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 12772 KB Output is correct
2 Correct 60 ms 12752 KB Output is correct
3 Correct 40 ms 8500 KB Output is correct
4 Correct 8 ms 2124 KB Output is correct
5 Correct 7 ms 1372 KB Output is correct
6 Correct 14 ms 2976 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 5900 KB Output is correct
2 Correct 27 ms 5956 KB Output is correct
3 Correct 27 ms 5840 KB Output is correct
4 Correct 28 ms 5916 KB Output is correct
5 Correct 27 ms 6060 KB Output is correct
6 Correct 37 ms 6432 KB Output is correct
7 Correct 29 ms 6096 KB Output is correct
8 Correct 26 ms 5824 KB Output is correct
9 Correct 34 ms 5712 KB Output is correct
10 Correct 25 ms 6092 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 8 ms 4040 KB Output is correct
13 Correct 9 ms 4040 KB Output is correct
14 Correct 8 ms 4040 KB Output is correct
15 Correct 8 ms 4040 KB Output is correct
16 Correct 8 ms 4040 KB Output is correct
17 Correct 8 ms 4040 KB Output is correct
18 Correct 8 ms 4040 KB Output is correct
19 Correct 8 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 332 KB Output is correct
23 Correct 8 ms 4040 KB Output is correct
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 12772 KB Output is correct
2 Correct 60 ms 12752 KB Output is correct
3 Correct 40 ms 8500 KB Output is correct
4 Correct 8 ms 2124 KB Output is correct
5 Correct 7 ms 1372 KB Output is correct
6 Correct 14 ms 2976 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -