QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#876010#9678. 网友小 Z 的树Felix720 0ms16316kbC++142.6kb2025-01-30 15:38:182025-01-30 15:38:19

Judging History

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

  • [2025-01-30 15:38:19]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:16316kb
  • [2025-01-30 15:38:18]
  • 提交

answer

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

const int N = 100010;
struct Path {int x, y;};
int n, dist[N], val_12[N], val_12_min, pt; bool path[N];
inline Path get_edge()
{
	Path res = {1, 2}; val_12_min = 1e9;
	for(int i = 3; i <= n; ++i)
		val_12[i] = query(1, 2, i), val_12_min = min(val_12_min, val_12[i]);
	if(val_12_min == 4)
	{
		int val_12_min_cnt = 0, pos_q = 0;
		for(int i = 3; i <= n; ++i)
			if(val_12[i] == val_12_min)
				++val_12_min_cnt, pos_q = i;
		if(val_12_min_cnt == 1 && in(pos_q, res.x, res.y))
		{
			path[res.x] = path[res.y] = path[pos_q] = true;
			pt = res.y, dist[pt] = 1; return {res.x, pos_q};
		}
		else {path[res.x] = path[res.y] = true; return res;}
	}
	else
	{
		vector < int > on_path, on_path_val; int on_path_max = -1;
		for(int i = 3; i <= n; ++i)
			if(val_12[i] == val_12_min)
				on_path.push_back(i), path[i] = true;
		path[res.x] = path[res.y] = true;
		if(on_path.size() == 2)
		{
			pt = res.y, dist[res.y] = 2;
			if(in(on_path[0], res.x, on_path[1])) return {res.x, on_path[0]};
			else return {res.x, on_path[1]};
		}
		dist[res.x] = val_12_min / 2 - 1; pt = res.x;
		for(int i = 0; i < (int)on_path.size() - 1; ++i)
		{
			int cur = query(res.x, on_path[i], on_path[i + 1]);
			on_path_val.push_back(cur); on_path_max = max(on_path_max, cur);
		}
		if(on_path_val[0] == on_path_max && on_path_val[1] != on_path_max) return {on_path[0], res.y};
		else if(on_path_val[(int)on_path_val.size() - 1] == on_path_max && on_path_val[(int)on_path_val.size() - 2] != on_path_max) return {on_path.back(), res.y};
		for(int i = 0; i < (int)on_path_val.size() - 1; ++i)
			if(on_path_val[i] == on_path_max && on_path_val[i + 1] == on_path_max)
				return {on_path[i + 1], res.y};
	}
}

pair < int, int > find_diameter(int task_id, int task_n)
{
	n = task_n; pt = 0;
	for(int i = 1; i <= n; ++i) path[i] = false, dist[i] = -1;
	if(n == 1) return {1, 1};
	if(n == 2) return {1, 2};
	Path rt = get_edge();
	for(int i = 1; i <= n; ++i)
	{
		if(path[i] || i == rt.x || i == rt.y) continue;
		dist[i] = query(i, rt.x, rt.y) / 2 - 1;
		if(dist[i] > dist[pt]) pt = i;
	}
	int len = dist[pt] + 1; pair < int, int > res = {0, 0};
	if(in(rt.x, pt, rt.y)) res = {pt, rt.y};
	else res = {pt, rt.x};
	for(int i = 1; i <= n; ++i)
	{
		if(i == pt || dist[i] == -1) continue;
		int cur = query(i, pt, rt.x);
		if(cur == 2 * (dist[i] + dist[pt] + 1))
		{
			if(cur / 2 > len)
			{
				len = cur / 2;
				res = {i, pt};
			}
		}
		else
		{
			if(cur - dist[i] - dist[pt] > len)
			{
				len = cur - dist[i] - dist[pt];
				res = {i, pt};
			}
		}
	}
	return res;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 16316kb

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:

WA

result:

wrong answer Wrong Answer

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%