QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#346192 | #4433. Kitten and Roomba | studentDL | AC ✓ | 282ms | 58036kb | C++14 | 2.1kb | 2024-03-07 22:37:13 | 2024-03-07 22:37:13 |
Judging History
answer
#include<algorithm>
#include<cstdio>
#include<cstring>
#define pii pair<int,int>
#define mk make_pair
#define ft first
#define se second
#define pb push_back
#define db double
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 1e18
using namespace std;
namespace IO{
#ifndef LOCAL
#define SIZE 30000
char in[SIZE],out[SIZE],*p1=in,*p2=in,*p3=out;
#define getchar() (p1==p2&&(p2=(p1=in)+fread(in,1,SIZE,stdin),p1==p2)?EOF:*p1++)
#define flush() (fwrite(p3=out,1,SIZE,stdout))
#define putchar(ch) (p3==out+SIZE&&flush(),*p3++=(ch))
class Flush{public:~Flush(){fwrite(out,1,p3-out,stdout);}}_;
#endif
template<typename type>
inline void read(type &x){
x=0;bool flag=0;char ch=getchar();
while(ch<'0'||ch>'9') flag^=ch=='-',ch=getchar();
while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
flag?x=-x:0;
}
template<typename type>
inline void write(type x,char ch=0){
x<0?x=-x,putchar('-'):0;static short Stack[50],top=0;
do Stack[++top]=x%10,x/=10;while(x);
while(top) putchar(Stack[top--]|48);
if(ch) putchar(ch);
}
}
using namespace IO;
#define M 1000005
int n,m,ini,cnt,head[M];
struct edge{
int nxt,v;
}e[M<<1];
void add(int u,int v){
e[++cnt]={head[u],v};
head[u]=cnt;
}
int fa[M],deg[M];
void dfs(int u,int f){
fa[u]=f;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].v;
if(v!=f) dfs(v,u);
}
}
db ans,dp[M],tag[M];
void solve(){
read(n),read(ini);
cnt=ans=0;
for(int i=1;i<=n;i++) head[i]=deg[i]=dp[i]=tag[i]=0;
dp[ini]=1;
for(int i=1,u,v;i<n;i++){
read(u),read(v);
add(u,v),add(v,u);
deg[u]++,deg[v]++;
}
dfs(1,0);
read(m);
for(int i=1,u;i<=m;i++){
read(u);
db val=dp[u]+tag[fa[u]];
ans+=val,dp[u]-=val;
dp[fa[u]]+=val/deg[u],tag[u]+=val/deg[u];
}
printf("%.10lf\n",ans);
}
int main(){
int T;read(T);
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 236ms
memory: 46888kb
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.6094173415 5.6105051393
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 81ms
memory: 14196kb
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.5837233171 4999999.0000000000 666788.7801028123
result:
ok 3 numbers
Test #3:
score: 0
Accepted
time: 67ms
memory: 16172kb
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.4745221743 2.1250000000 23.9549635077 0.0000000000 2.5000000000 3.9359626246 3.1068415455 5.5887925170 3.1066196464 1.7916666667 5.5555307176 0.0000000000 4.8683307759 3.4993287213 0.0000000000 3.1068519198 5.6728715898 5.6832847728 0.0000000000 3.0740004920 4.2690553373 3.1068533550 6.2634707432 ...
result:
ok 5050 numbers
Test #4:
score: 0
Accepted
time: 235ms
memory: 46768kb
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.4526409125 4.4466379969
result:
ok 2 numbers
Test #5:
score: 0
Accepted
time: 237ms
memory: 46928kb
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.8375541365 4.2715763974
result:
ok 2 numbers
Test #6:
score: 0
Accepted
time: 282ms
memory: 58036kb
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.8148148148 11.3320963664
result:
ok 2 numbers
Extra Test:
score: 0
Extra Test Passed