Submission #473722

# Submission time Handle Problem Language Result Execution time Memory
473722 2021-09-16T00:24:26 Z ntabc05101 Mag (COCI16_mag) C++14
12 / 120
445 ms 152300 KB
#include<bits/stdc++.h>
using namespace std;

const int mxN = 1000000;

bool choose[mxN];
vector<int> adj[mxN];
int ans = 0;
int d[mxN + 1];

void dfs(int u, int p = -1) {
  vector<int> v;
  int mx = -1, mx2 = -1;
  for (auto &to: adj[u]) {
    if (to != p) {
      dfs(to, u);
      if (choose[to]) {
        mx2 = max(mx2, d[to]);
        if (mx2 > mx) {
          swap(mx2, mx);
        }
      }
    }
  }

  if (choose[u]) {
    d[u] = 1;
    if (~mx) {
      ans = max(ans, mx + 1);
      d[u] = mx + 1;
    }
    if (~mx2) {
      ans = max(ans, mx + mx2);
    }
  }
}

int main() {
  cin.tie(0)->sync_with_stdio(0);

  int n; cin >> n;
  for (int i = 0, x, y; i < n - 1; i++) {
    cin >> x >> y; x--; y--;

    adj[x].push_back(y);
    adj[y].push_back(x);
  }

  int mn = 1e9;
  for (int i = 0, x; i < n; i++) {
    cin >> x;
    choose[i] = x == 1;
    mn = min(mn, x);
  }

  if (mn > 1) {
    cout << mn << "/1";
  }
  else {
    ans = 1;
    dfs(0);
    cout << "1/" << ans;
  }

  cout << endl;

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 23812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 352 ms 97852 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 23756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 445 ms 152300 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 403 ms 75164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 390 ms 78208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 28868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 368 ms 73700 KB Output is correct
2 Incorrect 442 ms 76340 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 75976 KB Output is correct
2 Incorrect 357 ms 50044 KB Output isn't correct