QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#380530#8575. Three Person Tree Gameucup-team1766#Compile Error//Python31.3kb2024-04-07 05:31:592024-04-07 05:32:00

Judging History

你现在查看的是最新测评结果

  • [2024-04-07 05:32:00]
  • 评测
  • [2024-04-07 05:31:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

void dfs(vector<int> tree[], vector<int> &par, int cur, int prev) {
  par[cur] = prev;
  for (int nei : tree[cur]) {
    if (nei != prev) {
      dfs(tree, par, nei, cur);
    }
  }
}

void solve() {
  int N;
  cin >> N;
  int a, b, c;
  cin >> a >> b >> c;
  a--; b--; c--;
  
  vector<int> tree[N];
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    tree[u].push_back(v);
    tree[v].push_back(u);
  }

  vector<int> par(N);
  dfs(tree, par, a, -1);

  vector<int> marks(N, -1);
  int cur = b;
  int cnt = 0;
  while (cur != -1) {
    marks[cur] = cnt;
    cur = par[cur];
    cnt++;
  }

  cur = c;
  cnt = 0;
  int adist, bdist, cdist, center;
  while (cur != -1) {
    if (marks[cur] >= 0) {
      bdist = marks[cur];
      cdist = cnt;
      center = cur;
      break;
    }
    cur = par[cur];
    cnt++;
  }

  cur = center;
  adist = 0;
  while (cur != a) {
    adist++;
    cur = par[cur];
  }

  if (adist < bdist && adist - 1 <= cdist) {
    cout << "A\n";
  } else if (bdist <= adist && bdist < cdist) {
    cout << "B\n";
  } else if (cdist <= bdist && cdist < adist - 1) {
    cout << "C\n";
  } else {
    cout << "DRAW\n";
  }
}

int main() {  
  cin.tie(0)->sync_with_stdio(0);
  int T; cin >> T; while (T--) solve();
}

Details

  File "answer.code", line 2
    using namespace std;
          ^^^^^^^^^
SyntaxError: invalid syntax