Submission #76643

# Submission time Handle Problem Language Result Execution time Memory
76643 2018-09-15T10:56:04 Z Shafin666 Dreaming (IOI13_dreaming) C++14
0 / 100
64 ms 14592 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;

struct edge {
    int to, cost;
    /*edge(int _to, int _cost) {
        to = _to;
        cost = _cost;
    }*/
};

const int MAX_N = 1e5;
vector<edge> adj[MAX_N]; vector<int> R;
bool visited[MAX_N];
int maxdist, one, two, point;
edge parent[MAX_N];

void dfs1(int u, int par, int val) {
    visited[u] = 1;
    int i, mx = 0;

    if(u == par && !adj[u].size()) {point = u; return;}

    for(i = 0; i < (int) adj[u].size(); i++) {
        edge v = adj[u][i];
        if(visited[v.to] || v.to == par) continue;

        if(v.cost + val > mx) point = v.to, mx = v.cost + val;
        dfs1(v.to, u, v.cost + val);
    }
}

void dfs2(int u, int par, int val) {
    visited[u] = 0;
    int i, mx = 0;

    if(u == par && !adj[u].size()) {
        point = u; maxdist = 0; edge v;
        v.cost = 0; v.to = u; parent[u] = v; 
        return;}

    for(i = 0; i < (int) adj[u].size(); i++) {
        edge v = adj[u][i];
        if(!visited[v.to] || v.to == par) continue;

        if(v.cost + val > mx) point = v.to, mx = v.cost + val, maxdist = mx;
        dfs2(v.to, u, v.cost + val);
        parent[v.to] = v; parent[v.to].to = u;


    } visited[u] = 1;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    int i, ans = 0;

    for(i = 0; i < M; i++) {
        edge v; v.to = B[i]; v.cost = T[i];
        adj[A[i]].push_back(v); v.to = A[i];
        adj[B[i]].push_back(v);
    }

    for(i = 0; i < N; i++) {
        if(visited[i]) continue; 
        dfs1(i, i, 0); one = point; 
        dfs2(one, one, 0); two = point;
        
        ans = max(ans, maxdist);

        int able = maxdist/2, now = 0, d = 0;
        
        if(one == two) {R.push_back(0); continue;}
        if(parent[two].to == one) {R.push_back(parent[two].cost); continue;}

        for(i = two; i != one; i = parent[i].to) {
            if(now + parent[i].cost >= able) {
                d = min(now, maxdist-parent[i].cost-now);
                d += parent[i].cost; R.push_back(d);
                break;
            } now += parent[i].cost;
        }
    } sort(R.begin(), R.end(), greater<int>());

    if(!M) return 2*L;
    if(R.size() > 1) ans = max(ans, R[0]+L+R[1]);
    if(R.size() > 2) ans = max(ans, R[1]+L+L+R[2]);

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 63 ms 14592 KB Output is correct
2 Correct 64 ms 14584 KB Output is correct
3 Correct 49 ms 10488 KB Output is correct
4 Correct 11 ms 4480 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 5248 KB Output is correct
7 Incorrect 5 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 14592 KB Output is correct
2 Correct 64 ms 14584 KB Output is correct
3 Correct 49 ms 10488 KB Output is correct
4 Correct 11 ms 4480 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 5248 KB Output is correct
7 Incorrect 5 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 14592 KB Output is correct
2 Correct 64 ms 14584 KB Output is correct
3 Correct 49 ms 10488 KB Output is correct
4 Correct 11 ms 4480 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 5248 KB Output is correct
7 Incorrect 5 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 6272 KB Output is correct
2 Correct 27 ms 6264 KB Output is correct
3 Correct 28 ms 6272 KB Output is correct
4 Correct 27 ms 6272 KB Output is correct
5 Correct 25 ms 6272 KB Output is correct
6 Correct 29 ms 6648 KB Output is correct
7 Correct 31 ms 6392 KB Output is correct
8 Correct 26 ms 6144 KB Output is correct
9 Correct 27 ms 6140 KB Output is correct
10 Correct 28 ms 6296 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 7 ms 4088 KB Output is correct
13 Correct 10 ms 4088 KB Output is correct
14 Correct 7 ms 4088 KB Output is correct
15 Correct 7 ms 4088 KB Output is correct
16 Correct 7 ms 4088 KB Output is correct
17 Correct 11 ms 4088 KB Output is correct
18 Correct 8 ms 4216 KB Output is correct
19 Correct 11 ms 4088 KB Output is correct
20 Incorrect 4 ms 2688 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 14592 KB Output is correct
2 Correct 64 ms 14584 KB Output is correct
3 Correct 49 ms 10488 KB Output is correct
4 Correct 11 ms 4480 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 5248 KB Output is correct
7 Incorrect 5 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 14592 KB Output is correct
2 Correct 64 ms 14584 KB Output is correct
3 Correct 49 ms 10488 KB Output is correct
4 Correct 11 ms 4480 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 17 ms 5248 KB Output is correct
7 Incorrect 5 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -