比赛 |
20160421x |
评测结果 |
AAAWWWWWWW |
题目名称 |
电子碰撞 |
最终得分 |
30 |
用户昵称 |
KZNS |
运行时间 |
0.003 s |
代码语言 |
C++ |
内存使用 |
0.28 MiB |
提交时间 |
2016-04-21 16:26:28 |
显示代码纯文本
//KZNS
#include <fstream>
#include <vector>
#include <queue>
#include <cstring>
#include <utility>
using namespace std;
//
ifstream fin ("electrics.in");
ofstream fout ("electrics.out");
const int Nmax = 23;
typedef pair<double, int> pr;
//
int N, M, A, B;
vector<int> gp[Nmax];
double ps[Nmax];
double kd[2][2][Nmax] = {0};
priority_queue<pr> Qls;
int ud;
bool pd[Nmax] = {0};
//
int main() {
fin >> N >> M >> A >> B;
ud = N;
int a, b;
for (int i = 0; i < M; i++) {
fin >> a >> b;
gp[a].push_back(b);
gp[b].push_back(a);
}
for (int i = 1; i <= N; i++)
fin >> ps[i];
bool f = true;
int ts = 1, ls = 0;
kd[ls][0][A] = 1;
kd[ls][1][B] = 1;
while (f && ud) {
f = false;
memset(kd[ts], 0, sizeof(kd[ts]));
for (int i = 1; i <= N; i++) {
if (kd[ls][0][i]) {
kd[ts][0][i] += (kd[ls][0][i] * ps[i]);
for (int j = 0; j < gp[i].size(); j++) {
f = true;
kd[ts][0][gp[i][j]] += kd[ls][0][i] * ((1-ps[i])/gp[i].size());
}
}
}
for (int i = 1; i <= N; i++) {
if (kd[ls][1][i]) {
kd[ts][1][i] += kd[ls][1][i] * ps[i];
for (int j = 0; j < gp[i].size(); j++) {
f = true;
kd[ts][1][gp[i][j]] += kd[ls][1][i] * ((1-ps[i])/gp[i].size());
}
}
}
for (int i = 1; i <= N; i++) {
if (kd[ts][0][i] && kd[ts][1][i]) {
if (!pd[i]) {
pd[i] = true;
ud--;
Qls.push(make_pair(kd[ts][0][i] * kd[ts][1][i], i));
}
}
}
ls = ts;
ts ^= 1;
}
while (!Qls.empty()) {
fout << Qls.top().second << endl;
Qls.pop();
}
return 0;
}
//UBWH