QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#859675#9678. 网友小 Z 的树Southern_Dynasty0 0ms16308kbC++141.8kb2025-01-17 21:38:222025-01-17 21:40:23

Judging History

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

  • [2025-01-17 21:40:23]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:16308kb
  • [2025-01-17 21:38:22]
  • 提交

answer

#include "diameter.h"
#include<bits/stdc++.h>
#define fst first
#define scd second
#define SZ(s) ((int)s.size())
#define all(s) s.begin(),s.end()
#define eb emplace_back
const int N=1e6+5;
using namespace std;
typedef pair<int,int> pii;
template<class T,class I> inline bool chkmax(T &a,I b){return b>a?a=b,1:0;}
template<class T,class I> inline bool chkmin(T &a,I b){return b<a?a=b,1:0;}
bool vis[N];
std::pair<int, int> find_diameter(int task_id, int n){
	if(n<=2) return pii(1,n);
	for(int i=1;i<=n;++i) vis[i]=0;
	vector<int> dis(n+1);
	int mn=1e9;
	for(int i=2;i<n;++i){
		dis[i]=query(1,i,n);
		chkmin(mn,dis[i]);
	}
	vector<int> chain;
	chain.eb(1);
	for(int i=2;i<n;++i){
		if(dis[i]==mn) chain.eb(i);
	}
	chain.eb(n);
	if(SZ(chain)==n) return pii(1,n); 
	int u=0,v=0;
	if(!in(chain[1],1,n)){
		u=n,v=1;
	}else{
		for(int i=2;i<n;++i){
			if(dis[i]==mn+2){
				u=i;
				break;
			}
		}
		mn=1e9;
		vector<int> rdis(n+1);
		for(int v:chain){
			rdis[v]=query(1,v,u);
			chkmin(mn,rdis[v]);
		}
		vector<int> black;
		for(int v:chain){
			if(rdis[v]==mn) black.eb(v),vis[v]=1;
		}
		vis[1]=vis[n]=0;
		pii res(1,0);
		for(int i=1;i<SZ(black);++i){
			int v=black[i],len=query(1,res.fst,v);
			if(len!=res.scd) res=pii(v,len);
		}
		v=res.fst;
		vis[u]=vis[v]=1;
	}
	vector<int> D(n+1);
	pii Lpoint(0,0);
	for(int i=1;i<=n;++i){
		if(!vis[i]){
			D[i]=query(u,v,i);
			if(D[i]==dis[i]-mn) D[i]=(D[i]-2)/2;
			else D[i]/=2;
			chkmax(Lpoint,pii(D[i],i));
		}
	}
	D[v]=1,vis[v]=0;
	pii Rpoint(0,0);
	vis[Lpoint.scd]=1;
	for(int i=1;i<=n;++i){
		if(!vis[i]){
			int x=query(u,Lpoint.fst,i)-D[Lpoint.fst]-D[i];
			chkmax(Rpoint,pii(x,i));
		}
	}
	chkmax(Rpoint,pii(D[Lpoint.scd],u));
	return pii(Lpoint.scd,Rpoint.scd);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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%