Submission #306051

# Submission time Handle Problem Language Result Execution time Memory
306051 2020-09-24T11:47:35 Z eriksuenderhauf Stations (IOI20_stations) C++17
0 / 100
979 ms 1024 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
  vector<int> deg(n);
  vector<vector<int>> adj(n);
  for (int i = 0; i < n - 1; i++)
    deg[u[i]]++, deg[v[i]]++, adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]);;
  vector<int> labels(n);
  // if (*max_element(deg.begin(), deg.end()) <= 2) {
  //   int r = min_element(deg.begin(), deg.end()) - deg.begin(), p = -1;
  //   labels[r] = 0;
  //   for (int i = 1; i < n; i++) {
  //     if (~p) adj[r].erase(find(adj[r].begin(), adj[r].end(), p));
  //     tie(r, p) = make_pair(adj[r][0], r);
  //     labels[r] = i;
  //   }
  // } else {
  //   iota(labels.begin(), labels.end(), 0);
  // }
  function<void(int,int,int)> dfs = [&](int u, int p, int l) {
    labels[u] = l;
    adj[u].erase(find(adj[u].begin(), adj[u].end(), p));
    if (!adj[u].empty())
      dfs(adj[u][0], u, l+1);
  };
  int r = max_element(deg.begin(), deg.end()) - deg.begin();
  int lo = 1; labels[r] = 0;
  for (int v: adj[r]) {
    dfs(v, r, lo);
    lo += 1000;
  }
  return labels;
}

int find_next_station(int s, int t, vector<int> c) {
  sort(c.begin(), c.end());
  if (s == 0)
    return ((t-1) / 1000) * 1000 + 1;
  if ((s-1) / 1000 == (t-1) / 1000)
    return s < t ? s-1 : s+1;
  return s-1;
  // set<int> tmp; for (int x: c) tmp.insert(x+1);
  // int y = t+1;
  // if (tmp.count(y)) return y-1;
  // while (y > 0) {
  //   y /= 2;
  //   if (tmp.count(y))
  //     return y-1;
  // }
  // return *min_element(c.begin(), c.end());
  // return s < t ? *max_element(c.begin(), c.end()) : *min_element(c.begin(), c.end());
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1005
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 384 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=3, label=1001
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 608 ms 1008 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 979 ms 768 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 550 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -