比赛 20160421x 评测结果 AAWAWWWEEE
题目名称 电子碰撞 最终得分 30
用户昵称 mikumikumi 运行时间 0.732 s
代码语言 C++ 内存使用 0.28 MiB
提交时间 2016-04-21 15:57:57
显示代码纯文本
#include<cstdio>
#include<vector>
#include<deque>
#include<iostream>
#include<algorithm>
using namespace std;
const int SIZEN=30;
const double zero=1e-6;
int N,M,A,B;
class poi
{
public:
	int a,b;
	double t;
};
deque<poi> Q;
double P[SIZEN];
vector<int> s[SIZEN];
void read()
{
	scanf("%d%d%d%d",&N,&M,&A,&B);
	int fr,to;
	for(int i=1;i<=M;i++)
	{
		scanf("%d%d",&fr,&to);
		s[fr].push_back(to);
		s[to].push_back(fr);
	}
	for(int i=1;i<=N;i++)
	{
		scanf("%lf",&P[i]);
	}
}
double gan[SIZEN];
int id[SIZEN];
bool cmp(int a,int b)
{
	return gan[a]>gan[b];
}
void work()
{
	Q.push_back((poi){A,B,1});
	while(!Q.empty())
	{
		poi A=Q.front();Q.pop_front();
		int a=A.a,b=A.b;
		//cout<<a<<" "<<b<<endl;
		//printf("%.5lf\n",A.t);
		if(A.t<zero) continue;
		if(a==b) 
		{
			gan[a]+=A.t;
			continue;
		}
		for(int i=0;i<=s[a].size();i++)
		{
			//cout<<a<<" "<<b<<endl;
			for(int j=0;j<=s[b].size();j++)
			{
				int ta,tb;
				double now=A.t;
				if(i==s[a].size()) ta=a,now*=P[a];
				else ta=s[a][i],now*=1.0/double(s[a].size())*(1.0-P[a]);
				if(j==s[b].size()) tb=b,now*=P[b];
				else tb=s[b][i],now*=1.0/double(s[b].size())*(1.0-P[b]);
				Q.push_back((poi){ta,tb,now});
			}
		}
	}
	for(int i=1;i<=N;i++) id[i]=i;
	sort(id+1,id+1+N,cmp);
	for(int i=1;i<=N;i++)
	{
		printf("%d\n",id[i]);
		//printf("%.5lf\n",gan[id[i]]);
	}
}
int main()
{
	freopen("electrics.in","r",stdin);
	freopen("electrics.out","w",stdout);
	read();
	work();
	return 0;
}