Submission #920283

# Submission time Handle Problem Language Result Execution time Memory
920283 2024-02-02T11:52:12 Z Arp Dreaming (IOI13_dreaming) C++17
18 / 100
51 ms 17488 KB
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;

using i64 = int;
const int N = 1e5;
vector<pair<int,int>> adj[N];
i64 down[N],up[N];
bool vis[N];
i64 mini = 1e9;
void dfs(int u){
  vis[u] = true;
  vector<i64> all;
  i64 maxi = -1e9;
  for(auto [v,w] : adj[u]){
    if(vis[v]) continue;
    down[v] = down[u] + w;
    dfs(v);  
    up[u] = max(up[u],up[v] + w);
  }
  for(auto [v,w] : adj[u]){
    up[v] = max(up[v],maxi + w);
    maxi = max(maxi,up[v] + w);
  }
  maxi = -1e9;
  reverse(adj[u].begin(),adj[u].end());
  for(auto [v,w] : adj[u]){
    up[v] = max(up[v],maxi + w);
    maxi = max(maxi,up[v] + w);
  }
}

void dfs2(int u,int p){
  for(auto [v,w] : adj[u]){
    if(v == p) continue;
    dfs2(v,u);  
  }
  mini = min(mini,max(down[u],up[u]));
}

int travelTime(int N,int M,int L,int A[],int B[],int T[]){
  for(int i = 0;i<N;i++){
    up[i] = down[i] = 0;
    vis[i] = false;
  }
  for(int i = 0;i<M;i++){
    adj[A[i]].emplace_back(B[i],T[i]);
    adj[B[i]].emplace_back(A[i],T[i]);
  }
  multiset<i64> ms;
  vector<i64> com;
  int cc = 0;
  int l = -1;
  for(int i = 0;i<N;i++){
    if(!vis[i] && adj[i].size() <= 1){
      mini = 1e9;
      dfs(i);
      dfs2(i,-1);
      ms.insert(mini);
      com.push_back(mini);
      l = i;
      cc ++;
    }
  }
  assert(cc - 1 == N - M - 1);
  if(cc == 1){
    i64 ans = 0;
    for(int i = 0;i<N;i++){
      ans = max(ans,max(up[i],down[i]));
    }
    return ans;
  }
  if(cc == 2){
    i64 sum = 0;
    while(ms.size() > 0){
      sum += *ms.begin();
      ms.erase(ms.begin());
    }
    return sum + (cc - 1) * L;
  }
  i64 ans = 1e9;
  for(i64 c : com){
    ms.erase(ms.find(c));
    i64 maxi1 = *(--ms.end());
    ms.erase(ms.find(maxi1));
    i64 maxi2 = *(--ms.end());
    ans = min(ans,max(maxi1 + maxi2 + 2 * L,maxi1 + c + L));
    ms.insert(c);
    ms.insert(maxi1);
  }
  return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:53:7: warning: variable 'l' set but not used [-Wunused-but-set-variable]
   53 |   int l = -1;
      |       ^
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 17488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 17488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 9688 KB Output is correct
2 Correct 47 ms 9944 KB Output is correct
3 Correct 41 ms 9676 KB Output is correct
4 Correct 40 ms 9940 KB Output is correct
5 Correct 51 ms 9948 KB Output is correct
6 Correct 48 ms 10452 KB Output is correct
7 Correct 43 ms 9940 KB Output is correct
8 Correct 39 ms 9684 KB Output is correct
9 Correct 39 ms 9684 KB Output is correct
10 Correct 43 ms 9940 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 39 ms 9684 KB Output is correct
13 Correct 45 ms 9680 KB Output is correct
14 Correct 39 ms 9680 KB Output is correct
15 Correct 38 ms 9680 KB Output is correct
16 Correct 39 ms 9680 KB Output is correct
17 Correct 47 ms 9680 KB Output is correct
18 Correct 38 ms 9680 KB Output is correct
19 Correct 41 ms 9680 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 2 ms 4700 KB Output is correct
23 Correct 44 ms 9680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 17488 KB Output isn't correct
2 Halted 0 ms 0 KB -