Submission #882065

# Submission time Handle Problem Language Result Execution time Memory
882065 2023-12-02T14:11:11 Z nikd Dreaming (IOI13_dreaming) C++17
0 / 100
57 ms 26724 KB
#include <bits/stdc++.h>
#include "dreaming.h"
#define MAXN 100001
using namespace std;

int f;
int max_dis;
int par[MAXN];
int cont=0;
vector<int> mintree;
bool vis[MAXN]={};
vector<pair<int, int>> adj[MAXN];
int dist[MAXN]={};

void dfs1(int v, int p){
    vis[v]=true;
    for(auto u: adj[v]){
        if(u.first!=p){
            dist[u.first]=dist[v]+u.second;
            if(dist[u.first]>max_dis){
                max_dis=dist[u.first];
                f=u.first;
            }
            dfs1(u.first, v);
        }
    }
}

void dfs2(int v, int p){
    par[v]=p;
    for(auto u: adj[v]){
        if(u.first!=p){
            dist[u.first]=dist[v]+u.second;
            if(dist[u.first]>max_dis){
                max_dis=dist[u.first];
                f=u.first;
            }
            dfs2(u.first, v);
        }
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]){
    for(int i = 0; i<M; i++){
        adj[A[i]].push_back({B[i], T[i]});
        adj[B[i]].push_back({A[i], T[i]});
    }
    for(int i = 0; i<N; i++){
        if(!vis[i]){
            mintree.push_back(INT_MAX);
            max_dis=0;
            f=0;
            dist[i]=0;
            dfs1(i, i);
            int a = f;
            dist[a]=0;
            max_dis=0;
            dfs2(a, a);
            int b = f;
            int d= max_dis/2;
            int last=-1;
            while(dist[b]>d){
                last=b;
                b=par[b];
            }
            if(last==-1){
                mintree[cont]=dist[b];
            }
            else{
                mintree[cont]=min(dist[last], max_dis-dist[b]);
            }
            cont++;
        }
    }
    sort(mintree.begin(), mintree.end());
    int sol;
    int n = mintree.size();
    
    if(n==2){
        sol = mintree[0]+mintree[1]+L;
    }
    if(n==1) sol =mintree[0];
    else{
        sol=max(mintree[n-1]+mintree[n-2]+L, mintree[n-2]+mintree[n-3]+2*L);
    }
    
    
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:76:9: warning: variable 'sol' set but not used [-Wunused-but-set-variable]
   76 |     int sol;
      |         ^~~
dreaming.cpp:88:1: warning: no return statement in function returning non-void [-Wreturn-type]
   88 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 26724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 8796 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 26724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 13872 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 8796 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 26724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -