답안 #76649

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76649 2018-09-15T11:05:59 Z Shafin666 꿈 (IOI13_dreaming) C++14
0 / 100
72 ms 27512 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+7;
vector<edge> adj[MAX_N]; vector<int> R;
bool visited[MAX_N];
int maxdist, one, two, point;
edge parent[1005];

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;

        for(i = two; i != one; i = parent[i].to) {
            if(d + parent[i].cost > able) {
                d = min(d + parent[i].cost, maxdist-d);
                break;
            } d += parent[i].cost;
        } R.push_back(d);
    } 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;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:71:31: warning: unused variable 'now' [-Wunused-variable]
         int able = maxdist/2, now = 0, d = 0;
                               ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 72 ms 27512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 72 ms 27512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 72 ms 27512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 10048 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 72 ms 27512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 72 ms 27512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -