Submission #468920

# Submission time Handle Problem Language Result Execution time Memory
468920 2021-08-30T07:56:31 Z Soumya1 Dreaming (IOI13_dreaming) C++17
0 / 100
56 ms 13380 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5;
vector<pair<int, int>> ad[mxN];
bool vis[mxN];
int dp[mxN][2];
int mn = 1e9;
int ans = 0;
void dfs(int node) {
  vis[node] = true;
  for (auto [child, w] : ad[node]) {
    if (vis[child]) continue;
    dfs(child);
    if (dp[child][1] + w >= dp[node][1]) {
      dp[node][0] = dp[node][1];
      dp[node][1] = dp[child][1] + w;
    } else if (dp[child][1] + w > dp[node][0]) {
      dp[node][0] = dp[child][1] + w;
    }
  }
  ans = max(ans, dp[node][1] + dp[node][0]);
}
void dfs1(int node, int par, int cur) {
  mn = min(mn, max(cur, dp[node][1]));
  for (auto [child, w] : ad[node]) {
    if (child == par) continue;
    dfs1(child, node, max(cur, (dp[node][1] == dp[child][1] + w ? dp[node][0] : dp[node][1])) + w);
  } 
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
  for (int i = 0; i < m; i++) {
    ad[a[i]].push_back({b[i], t[i]});
    ad[b[i]].push_back({a[i], t[i]});
  }
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      dfs(i);
      mn = 1e9;
      dfs1(i, -1, 0);
      v.push_back(mn);
    }
  }
  sort(v.rbegin(), v.rend());
  if (v.size() >= 1) {
    ans = max(ans, v[0]);
  }
  if (v.size() >= 1) {
    ans = max(ans, v[0] + v[1] + l);
  }
  if (v.size() >= 2) {
    ans = max(ans, v[1] + v[2] + 2 * l);
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 56 ms 13380 KB Output is correct
2 Correct 52 ms 12880 KB Output is correct
3 Correct 35 ms 11432 KB Output is correct
4 Correct 8 ms 4224 KB Output is correct
5 Correct 7 ms 3532 KB Output is correct
6 Correct 13 ms 4940 KB Output is correct
7 Incorrect 2 ms 2636 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Incorrect 2 ms 2636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 13380 KB Output is correct
2 Correct 52 ms 12880 KB Output is correct
3 Correct 35 ms 11432 KB Output is correct
4 Correct 8 ms 4224 KB Output is correct
5 Correct 7 ms 3532 KB Output is correct
6 Correct 13 ms 4940 KB Output is correct
7 Incorrect 2 ms 2636 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 6488 KB Output is correct
2 Correct 23 ms 6596 KB Output is correct
3 Correct 23 ms 6488 KB Output is correct
4 Correct 27 ms 6604 KB Output is correct
5 Correct 22 ms 6560 KB Output is correct
6 Correct 28 ms 7060 KB Output is correct
7 Correct 24 ms 6732 KB Output is correct
8 Correct 28 ms 6480 KB Output is correct
9 Correct 23 ms 6404 KB Output is correct
10 Correct 32 ms 6724 KB Output is correct
11 Correct 2 ms 2648 KB Output is correct
12 Correct 6 ms 3784 KB Output is correct
13 Correct 7 ms 3912 KB Output is correct
14 Correct 6 ms 3784 KB Output is correct
15 Correct 6 ms 3884 KB Output is correct
16 Correct 5 ms 3796 KB Output is correct
17 Correct 5 ms 3548 KB Output is correct
18 Correct 6 ms 4036 KB Output is correct
19 Correct 5 ms 3784 KB Output is correct
20 Incorrect 2 ms 2636 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Incorrect 2 ms 2636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 13380 KB Output is correct
2 Correct 52 ms 12880 KB Output is correct
3 Correct 35 ms 11432 KB Output is correct
4 Correct 8 ms 4224 KB Output is correct
5 Correct 7 ms 3532 KB Output is correct
6 Correct 13 ms 4940 KB Output is correct
7 Incorrect 2 ms 2636 KB Output isn't correct
8 Halted 0 ms 0 KB -