Submission #205096

# Submission time Handle Problem Language Result Execution time Memory
205096 2020-02-27T22:57:41 Z Haunted_Cpp Torrent (COI16_torrent) C++17
0 / 100
197 ms 25852 KB
#include <bits/stdc++.h>
using namespace std;
 
#define FOR(i, a, b) for (int i = a; i < (int) b; i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define f first
#define s second
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
 
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};

const int N = 3e5 + 5;

vvi g (N);
int subtree [N], tempo [N];

int dfs (int node, int p) {
  subtree[node] = 0;
  GO (to, g[node]) {
    if (to != p) {
      dfs (to, node);
      subtree[node] += subtree[to];
    }
  }
  return subtree[node] = subtree[node] + 1;
}

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, A, B, mx = 0;
  cin >> n >> A >> B;
  --A; --B;
  F0R (i, n - 1) {
    int st, et;
    cin >> st >> et;
    --st; --et;
    g[st].eb(et);
    g[et].eb(st);
  }
  dfs (0, -1);
  F0R (i, N) tempo[i] = 1e9;
  queue<int> q;
  q.push(A);
  q.push(B);
  tempo[A] = tempo[B] = 0;
  while(!q.empty()) {
    int node = q.front();
    int timer = tempo[node];
    mx = max (mx, timer);
    q.pop();
    vpii where_to_go;
    GO (to, g[node]) {
      where_to_go.eb(subtree[to], to);
    }
    sort (rall(where_to_go));
    GO (to, where_to_go) {
      if (tempo[to.s] > timer + 1) {
        ++timer;
        tempo[to.s] = timer;
        q.push(to.s);
      }
    }
  }
  cout << mx << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 8696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 197 ms 25852 KB Output isn't correct
2 Halted 0 ms 0 KB -