QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#663879#4433. Kitten and RoombaYaeMik0AC ✓1561ms147188kbC++231.3kb2024-10-21 18:06:062024-10-21 18:06:11

Judging History

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

  • [2024-10-21 18:06:11]
  • 评测
  • 测评结果:AC
  • 用时:1561ms
  • 内存:147188kb
  • [2024-10-21 18:06:06]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxn = 2100000;

int n,m,S;
double ans;
double sum[maxn],se[maxn];
int d[maxn];
vector< pair<int,int> >E[maxn];

int dfn[maxn],dfi;
void dfs(const int x,const int fa)
{
	dfn[x]=++dfi;
	for(auto [y,i]:E[x]) if(y!=fa)
		dfs(y,x);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int Tcase; cin>>Tcase;
	while(Tcase--)
	{
		cin>>n>>S;
		for(int i=1;i<=n;i++)
		{
			sum[i]=0;
			d[i]=0;
			vector< pair<int,int> >_;
			E[i].swap(_);
		}
		for(int i=1;i<=n*2;i++) se[i]=0;
				
		//map< pair<int,int>,int >mp;
		for(int i=1;i<n;i++)
		{
			int x,y; cin>>x>>y;
			d[x]++; d[y]++;
			E[x].emplace_back(y,i);
			E[y].emplace_back(x,i);
			//mp[make_pair(x,y)]=i;
			//mp[make_pair(y,x)]=n+i;
		}
		dfi=0; dfs(1,0);
		ans=0;
		
		cin>>m;
		vector<int>xi(m+5);
		for(int i=1;i<=m;i++) cin>>xi[i];
		
		sum[S]=1;
		for(int i=1,las=0;i<=m;i++)
		{
			int x=xi[i];
			if(x==S && ans==0)
			{
				ans=1;
			}
			if(las)
			{
				int ei;
				if(dfn[las]<dfn[x]) ei=dfn[x];
				else ei=n+dfn[las];
				double temp= (sum[las]-se[ei])/d[las];
				se[ei]=sum[las];
				ans+=temp;
				sum[x]+=temp;
			}
			las=x;
		}
		cout<<fixed<<setprecision(12)<<ans<<'\n';
	}
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1345ms
memory: 122552kb

input:

2
1000000 315562
969409 917725
324847 719085
524235 603427
576843 433171
75335 238378
266746 487233
80422 95099
594363 96140
858172 261406
958326 466109
233845 350950
863969 345645
689972 81395
395383 27274
93913 208983
523722 380358
108074 172341
130041 692304
737158 383812
752080 33646
154356 6672...

output:

5.609417341487
5.610505139293

result:

ok 2 numbers

Test #2:

score: 0
Accepted
time: 366ms
memory: 29116kb

input:

3
3 3
2 1
2 3
4000000
2 1 2 1 2 3 2 3 2 3 2 1 2 3 2 1 2 3 2 1 2 3 2 3 2 3 2 3 2 1 2 3 2 1 2 3 2 1 2 1 2 1 2 1 2 1 2 1 2 3 2 1 2 3 2 3 2 3 2 3 2 1 2 1 2 1 2 1 2 1 2 1 2 3 2 1 2 1 2 3 2 3 2 1 2 3 2 3 2 1 2 1 2 1 2 3 2 3 2 3 2 3 2 1 2 3 2 1 2 1 2 3 2 3 2 1 2 3 2 3 2 3 2 3 2 3 2 1 2 3 2 1 2 3 2 1 2 1 2 ...

output:

2000496.583899351070
4999999.000000000000
666788.779764503124

result:

ok 3 numbers

Test #3:

score: 0
Accepted
time: 427ms
memory: 10540kb

input:

5050
178 146
7 29
45 132
140 19
48 80
50 147
24 98
176 94
45 124
3 161
36 94
4 33
24 81
94 123
4 15
12 170
152 95
55 152
24 131
94 32
121 150
37 167
146 80
65 152
99 150
24 60
8 29
5 163
64 50
93 67
19 13
24 153
80 152
29 120
67 59
138 48
5 17
19 35
94 116
57 142
80 53
6 45
29 80
150 40
47 161
62 94...

output:

3.474522174310
2.125000000000
23.954963507658
0.000000000000
2.500000000000
3.935962624588
3.106841545496
5.588792516971
3.106619646407
1.791666666667
5.555530717632
0.000000000000
4.868330775897
3.499328721323
0.000000000000
3.106851919765
5.672871589793
5.683284772799
0.000000000000
3.074000492018...

result:

ok 5050 numbers

Test #4:

score: 0
Accepted
time: 1323ms
memory: 126296kb

input:

2
1000000 315562
679816 923554
749026 119526
400361 398944
729861 38631
237682 984276
240713 304346
923009 28429
705303 35145
281546 196216
128884 76719
542097 696978
832261 79936
617939 739512
639643 738806
304260 52873
63627 552308
627252 842013
683909 619035
326617 406438
159332 82575
823300 4115...

output:

4.452640912528
4.446637996859

result:

ok 2 numbers

Test #5:

score: 0
Accepted
time: 1287ms
memory: 128048kb

input:

2
1000000 315562
575035 646638
803204 719085
692015 374086
755314 193304
776395 55874
976706 805712
217914 823156
919201 953003
149774 16297
569437 50630
191605 6485
126613 286636
24494 152244
160536 434534
692015 362579
892731 521828
374895 872623
583943 946248
226984 256881
130161 826314
247361 45...

output:

5.837554136541
4.271576397399

result:

ok 2 numbers

Test #6:

score: 0
Accepted
time: 1561ms
memory: 147188kb

input:

2
1000000 941595
260117 135833
814046 740606
747365 965295
391550 71159
728551 704248
786875 854209
980320 968654
685130 721737
464879 19066
485673 803636
761076 467129
693561 787751
69739 373415
994214 367199
13100 494671
996272 547209
992937 103917
484331 476434
493297 779246
882922 78092
622726 3...

output:

8.814814814815
11.332096366381

result:

ok 2 numbers

Extra Test:

score: 0
Extra Test Passed