QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#863498#9678. 网友小 Z 的树cooluo0 0ms0kbC++232.4kb2025-01-19 18:09:102025-01-19 18:09:10

Judging History

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

  • [2025-01-19 18:09:10]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2025-01-19 18:09:10]
  • 提交

answer

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

#define pii pair<int, int>
#define mkpr make_pair
#define vi vector<int>
#define all(c) (c).begin(), (c).end()
#define rep(i, l, r) for (int i(l), i##End(r); i <= i##End; i = -~i)
#define ti3 tuple<int, int, int>

int n, m;
map<ti3, int> mp;

int qry(int u, int v, int w) {
    vi _({u, v, w}); sort(all(_));
    u = _[0], v = _[1], w = _[2];
    ti3 x(u, v, w);
    if (mp.count(x)) return mp[x];
    return mp[x] = query(u, v, w);
}

pii find_diameter(int task_id, int n) {
    mp.clear();
    if (n <= 2) return mkpr(1, n);
    int u = 1, v = 2, w = 3;
    // int u = rnd(1, n), v, w;
    // while ((v = rnd(1, n)) == u);
    // while ((w = rnd(1, n)) == v || w == u);
    rep(i, 1, n) if (i != u && i != v && i != w) {
        // printf("@ %d: (%d %d %d) (%d %d %d) -> ", i, u, v, w, i, v, w);
        if (qry(u, v, w) < qry(i, v, w)) u = i;
        // printf("(%d %d %d)\n", u, v, w);
    }
    rep(i, 1, n) if (i != u && i != v && i != w) {
        // printf("# %d: (%d %d %d) (%d %d %d) -> ", i, u, v, w, i, v, w);
        if (qry(u, v, w) < qry(u, i, w)) v = i;
        // printf("(%d %d %d)\n", u, v, w);
    }
    rep(i, 1, n) if (i != u && i != v && i != w) {
        // printf("$ %d: (%d %d %d) (%d %d %d) -> ", i, u, v, w, i, v, w);
        if (qry(u, v, w) < qry(u, v, i)) w = i;
        // printf("(%d %d %d)\n", u, v, w);
    }
    int x = 0;
    rep(i, 1, n) if (i != u && i != v && i != w)
        if (!x || qry(u, v, i) < qry(u, v, x)) x = i;
    printf("%d %d %d | %d\n", u, v, w, x);
    // for (auto [_, x] : mp) {
    //     auto [_u, _v, _w] = _;
    //     printf("[%d %d %d]: %d\n", _u, _v, _w, x);
    // }
    if (!x) {
        if (in(u, v, w)) return mkpr(v, w);
        if (in(v, u, w)) return mkpr(u, w);
        return mkpr(u, v);
    }
    if (in(u, v, x)) {
        return mkpr(v, w);
    }
    if (in(x, u, w)) {
        int a = qry(u, v, x) >> 1, b = qry(u, w, x) >> 1, c = qry(u, v, w) - a - b;
        int d = max({a, b, c});
        if (d == a) return mkpr(u, v);
        if (d == b) return mkpr(u, w);
        return mkpr(v, w);
    }
    int a = qry(u, v, x) >> 1, b = qry(v, w, x) >> 1, c = qry(u, v, w) - a - b;
    int d = max({a, b, c});
    if (d == a) return mkpr(u, v);
    if (d == b) return mkpr(v, w);
    return mkpr(u, w);
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

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:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

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:

0%