QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865972 | #9678. 网友小 Z 的树 | masterhuang | 16 | 19ms | 13920kb | C++23 | 1.5kb | 2025-01-22 10:00:19 | 2025-01-22 10:00:20 |
Judging History
answer
#include "diameter.h"
#include <bits/stdc++.h>
#define LL long long
#define P pair<int,int>
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
mt19937 rnd(time(0));
const int N=1e5+5,inf=1e9;
int n,f[N],p[N];bool ban[N];
P find_diameter(int id,int n)
{
::n=n;if(n==1) return {1,1};
if(n==2) return {1,2};
if(n==3)
{
bool o1=in(1,2,3),o2=in(2,1,3);
if(o1) return {2,3};
if(o2) return {1,3};return {1,2};
}fill(f+1,f+1+n,inf+1);
if(n>1e4)
{
iota(p+1,p+1+n,1);shuffle(p+1,p+1+n,rnd);fill(ban+1,ban+1+n,0);
for(int i=1;i<=min(n,30);i++) ban[p[i]]=1;
}
int x=1,y=2,z=3,d=query(1,2,3),mn=inf;
for(int i=1;i<=n;i++) if(i!=y&&i!=z&&!ban[i])
{
int D=query(i,y,z);
if(D>d) d=D,x=i;
}
for(int i=1;i<=n;i++) if(i!=x&&i!=z&&!ban[i])
{
int D=query(x,i,z);
if(D>d) d=D,y=i;
}
for(int i=1;i<=n;i++) if(i!=x&&i!=y&&!ban[i])
{
int D=query(x,y,i);mn=min(mn,f[i]=D);
if(D>d) d=D,z=i;
}
if(f[z]==mn) return {x,y};
bool o1=in(x,y,z),o2=in(y,x,z);
if(o1) return {y,z};if(o2) return {x,z};
vector<int>g;int d1=mn,d2=inf,d3=inf,mx,c2=1,c3=1;
for(int i=1;i<=n;i++) if(f[i]==mn) g.push_back(i);
shuffle(g.begin(),g.end(),rnd);
for(int i=0;i<min((int)g.size(),30);i++)
{
int n2=query(x,z,g[i]),n3=query(y,z,g[i]);
c2+=(n2==d2);c3+=(n3==d3);
if(n2<d2) c2=1,d2=n2;if(n3<d3) c3=1,d3=n3;
}
if(c2<2) d2=-1;if(c3<2) d3=-1;
mx=max({d1,d2,d3});
if(d1==mx) return {x,y};
if(d2==mx) return {x,z};return {y,z};
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 16
Accepted
Test #1:
score: 16
Accepted
time: 2ms
memory: 8112kb
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: 19ms
memory: 13920kb
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%