Submission #728369

# Submission time Handle Problem Language Result Execution time Memory
728369 2023-04-22T10:02:17 Z NeroZein Dreaming (IOI13_dreaming) C++17
0 / 100
57 ms 16088 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 + 1); 
  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]); 
        }
      }
    }
    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 50 ms 16088 KB Output is correct
2 Correct 57 ms 15632 KB Output is correct
3 Correct 41 ms 13764 KB Output is correct
4 Correct 8 ms 4540 KB Output is correct
5 Correct 7 ms 3796 KB Output is correct
6 Correct 12 ms 5536 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 1 ms 2644 KB Output is correct
2 Correct 1 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 50 ms 16088 KB Output is correct
2 Correct 57 ms 15632 KB Output is correct
3 Correct 41 ms 13764 KB Output is correct
4 Correct 8 ms 4540 KB Output is correct
5 Correct 7 ms 3796 KB Output is correct
6 Correct 12 ms 5536 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 22 ms 7500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 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 50 ms 16088 KB Output is correct
2 Correct 57 ms 15632 KB Output is correct
3 Correct 41 ms 13764 KB Output is correct
4 Correct 8 ms 4540 KB Output is correct
5 Correct 7 ms 3796 KB Output is correct
6 Correct 12 ms 5536 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -