QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#135478 | #4433. Kitten and Roomba | Sommohito# | WA | 1456ms | 197328kb | C++20 | 1.6kb | 2023-08-05 16:02:32 | 2023-08-05 16:02:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#ifdef APURBA
#include "DEBUG_TEMPLATE.h"
#else
#define HERE
#define debug(args...)
#endif
#define ALL(x) x.begin(),x.end()
const int M=5e6+5,N=1e6+5;
int n;
vector<int>e[N];
bool vis[M];
int m;
vector<int>all;
ld dp[M];
vector<int>pos[N];
ld run(int idx)
{
if(idx>=5000)
return 0;
if(vis[idx]==1)
return dp[idx];
int node=all[idx];
vis[idx]=1;
ld sum=0;
for(int u:e[node])
{
auto itr=lower_bound(pos[u].begin(),pos[u].end(),idx);
if(itr!=pos[u].end())
{
sum+=(1+run(*itr));
}
}
sum/=(int)e[node].size();
return dp[idx]=sum;
}
void TEST_CASES()
{
int c;
cin>>n>>c;
for(int i=1;i<=n;i++)
pos[i].clear(),e[i].clear();
for(int i=0;i<n-1;i++)
{
int u,v;
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
cin>>m;
all.resize(m);
for(int i=0;i<m;i++)
{
vis[i]=0;
cin>>all[i];
pos[all[i]].push_back(i);
}
if(pos[c].size()==0)
{
cout<<0<<"\n";
}
else {
cout<<fixed<<setprecision(10)<<1+run(pos[c][0])<<"\n";
}
}
/*
*/
int32_t main()
{
#ifndef APURBA
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#endif
//freopen("input.txt","r",stdin);
//freopen("out1.txt","w",stdout);
int t=1;
cin>>t;
while(t--)
{
TEST_CASES();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1456ms
memory: 197328kb
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:
2.7504558565 2.7481610709
result:
wrong answer 1st numbers differ - expected: '5.60942', found: '2.75046', error = '0.50967'