QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#298239#4433. Kitten and RoombaPhantomThreshold#WA 1295ms154004kbC++201.3kb2024-01-05 21:08:512024-01-05 21:08:51

Judging History

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

  • [2024-01-05 21:08:51]
  • 评测
  • 测评结果:WA
  • 用时:1295ms
  • 内存:154004kb
  • [2024-01-05 21:08:51]
  • 提交

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[x];
				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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1295ms
memory: 154004kb

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.529345602459
1.712253138114

result:

wrong answer 1st numbers differ - expected: '5.60942', found: '2.52935', error = '0.54909'