QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#861897#9678. 网友小 Z 的树hcywoi16 17ms11860kbC++232.8kb2025-01-18 20:29:302025-01-18 20:29:42

Judging History

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

  • [2025-01-18 20:29:42]
  • 评测
  • 测评结果:16
  • 用时:17ms
  • 内存:11860kb
  • [2025-01-18 20:29:30]
  • 提交

answer

#include "diameter.h"
#include <bits/stdc++.h>

std::pair<int, int> find_diameter(int task_id, int n) {
  if (n == 1) {
    return {1, 1};
  }
  if (n == 2) {
    return {1, 2};
  }
  if (n == 3) {
    if (in(1, 2, 3)) {
      return {2, 3};
    }
    if (in(2, 1, 3)) {
      return {1, 3};
    }
    return {1, 2};
  }
  if (n == 4) {
    int cnt = 0;
    for (int i = 1; i <= 4; i++) {
      for (int j = i + 1; j <= 4; j++) {
        for (int k = j + 1; k <= 4; k++) {
          cnt += query(i, j, k) == 4;
        }
      }
    }
    if (cnt == 3) {
      if (in(1, 2, 3)) {
        return {2, 3};
      }
      if (in(2, 1, 3)) {
        return {1, 3};
      }
      return {1, 2};
    }
    for (int i = 1; i <= 4; i++) {
      for (int j = i + 1; j <= 4; j++) {
        cnt = 0;
        for (int k = 1; k <= 4; k++) {
          if (i != k && j != k) {
            cnt += query(i, j, k) == 6;
          }
        }
        if (cnt == 2) {
          return {i, j};
        }
      }
    }
    assert(false);
  }

  int s = 0;
  std::vector d(6, std::vector(6, std::vector<int>(6)));

  auto A1 = [&](int i, int j, int k) {
    int a[3] = {i, j, k};
    std::sort(a, a + 3);
    return d[a[0]][a[1]][a[2]];
  };

  for (int i = 1; i <= 5; i++) {
    for (int j = i + 1; j <= 5; j++) {
      for (int k = j + 1; k <= 5; k++) {
        d[i][j][k] = query(i, j, k);
        s += d[i][j][k];
      }
    }
  }
  s /= 3;

  std::vector<std::map<int, int>> dis(n + 1);
  for (int i = 1; i <= 5; i++) {
    for (int j = i + 1; j <= 5; j++) {
      std::vector<int> t;
      for (int k = 1; k <= 5; k++) {
        if (i != k && j != k) {
          t.push_back(k);
        }
      }
      int v = A1(i, t[0], t[1]) + A1(j, t[0], t[1]) + A1(i, t[0], t[2]) + A1(j, t[0], t[2]) + A1(i, t[1], t[2]) + A1(j, t[1], t[2]);
      v /= 2;
      dis[i][j] = s - v;
    }
  }

  auto A2 = [&](int i, int j) {
    return dis[std::min(i, j)][std::max(i, j)];
  };

  int len = -1;
  int x, y, z;
  for (int i = 1; i <= 5; i++) {
    for (int j = i + 1; j <= 5; j++) {
      if (A2(i, j) > len) {
        len = A2(i, j);
        x = i;
        y = j;
      }
    }
  }
  for (int i = 1; i <= 5; i++) {
    if (i != x && i != y) {
      z = i;
      break;
    }
  }

  for (int i = 6; i <= n; i++) {
    int a = query(x, y, i);
    int b = query(x, z, i);
    int c = query(y, z, i);
    int d = a + b + c;
    d -= A2(x, y) + A2(x, z) + A2(y, z);
    d /= 2;
    dis[z][i] = d - (a - A2(x, y));
    dis[y][i] = d - (b - A2(x, z));
    dis[x][i] = d - (c - A2(y, z));
    if (dis[x][i] > len) {
      len = dis[x][i];
      z = y;
      y = i;
    }
    if (dis[y][i] > len) {
      len = dis[y][i];
      z = x;
      x = i;
    }
  }
  return {x, y};
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 16
Accepted

Test #1:

score: 16
Accepted
time: 4ms
memory: 10308kb

input:

1 100
25
1 3
2 18
3 8
4 18
5 14
6 22
7 18
8 10
9 11
10 12
11 25
12 16
13 11
14 17
15 17
16 25
17 2
18 20
19 18
20 12
21 1
22 17
23 14
24 1
50
1 37
2 27
3 10
4 25
5 16
6 17
7 10
8 36
9 16
10 6
11 48
12 2
13 28
14 30
15 10
16 44
17 31
18 1
19 6
20 7
21 30
22 42
23 45
24 23
25 27
26 39
27 45
28 48
29 4...

output:

correct

result:

ok Correct

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #2:

score: 0
Wrong Answer
time: 17ms
memory: 11860kb

input:

2 2006
42
1 32
2 4
3 6
4 29
5 1
6 42
7 10
8 16
9 6
10 25
11 42
12 8
13 36
14 8
15 17
16 3
17 6
18 21
19 23
20 31
21 42
22 6
23 32
24 7
25 27
26 34
27 31
28 6
29 41
30 20
31 9
32 7
33 3
34 5
35 5
36 1
37 8
38 14
39 15
40 12
41 22
95
1 94
2 88
3 13
4 71
5 37
6 45
7 87
8 24
9 76
10 54
11 69
12 95
13 90...

output:

WA

result:

wrong answer Wrong Answer

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%

Subtask #8:

score: 0
Skipped

Dependency #7:

0%

Subtask #9:

score: 0
Skipped

Dependency #8:

0%

Subtask #10:

score: 0
Skipped

Dependency #9:

0%

Subtask #11:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%