Submission #728360

# Submission time Handle Problem Language Result Execution time Memory
728360 2023-04-22T09:59:18 Z NeroZein Dreaming (IOI13_dreaming) C++17
0 / 100
54 ms 16892 KB
#include "dreaming.h"
#include <bits/stdc++.h>
 
using namespace std; 
 
const int NN = 100005;
 
int a[NN], b[NN], t[NN];
vector<pair<int, int>> g[NN]; 
int vis[NN]; 
int mx[NN], mx2[NN]; 
int far[NN];
 
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  int n, m, l;
  n = N, m = M, l = L; 
  for (int i = 0; i < m; ++i) {
    a[i] = A[i];
    b[i] = B[i];
    t[i] = T[i];
  }
  for (int i = 0; i < m; ++i) { 
    g[a[i]].emplace_back(b[i], t[i]);
    g[b[i]].emplace_back(a[i], t[i]); 
  }
  int ncc = 0; 
  vector<int> d(n); 
  function<void(int, int)> Dfs = [&](int v, int p) {
    vis[v] = ncc; 
    for (auto [u, w] : g[v]) {
      if (u != p) {
        Dfs(u, v); 
        mx2[v] = max(mx2[v], mx[u] + w); 
        if (mx2[v] > mx[v]) {
          swap(mx2[v], mx[v]); 
        }
      }
    }
    //cout << " v: " << mx[v] << ' ' << mx2[v] << '\n';
    d[ncc] = max(d[ncc], mx[v] + mx2[v]); 
  };
  vector<int> mn(n + 1, 1e9); 
  function<void(int, int, int)> Dfs2 = [&](int v, int p, int up) {
    far[v] = max(mx[v], up); 
    mn[ncc] = min(mn[ncc], far[v]); 
    for (auto [u, w] : g[v]) {
      if (u == p) continue; 
      int nup = mx[v] + w == mx[u] ? mx2[v] : mx[v]; 
      Dfs2(u, v, nup); 
    }
  };
  for (int i = 0; i < n; ++i) {
    if (!vis[i]) {
      //cout << " I: " << i << '\n'; 
      ncc++; 
      Dfs(i, i); 
      Dfs2(i, i, 0); 
    }
  }
  //cout << " d: " << d[1] << ' ' << d[2] << '\n';
  int ans = max({d[1], d[2], l + mn[1] + mn[2]});
  return ans; 
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 16300 KB Output is correct
2 Correct 54 ms 16892 KB Output is correct
3 Correct 32 ms 14648 KB Output is correct
4 Correct 9 ms 4756 KB Output is correct
5 Correct 6 ms 3924 KB Output is correct
6 Correct 13 ms 5844 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2664 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 1 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 16300 KB Output is correct
2 Correct 54 ms 16892 KB Output is correct
3 Correct 32 ms 14648 KB Output is correct
4 Correct 9 ms 4756 KB Output is correct
5 Correct 6 ms 3924 KB Output is correct
6 Correct 13 ms 5844 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 7944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2664 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 1 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 16300 KB Output is correct
2 Correct 54 ms 16892 KB Output is correct
3 Correct 32 ms 14648 KB Output is correct
4 Correct 9 ms 4756 KB Output is correct
5 Correct 6 ms 3924 KB Output is correct
6 Correct 13 ms 5844 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -