链接:

https://nanti.jisuanke.com/t/41402

题意:

To seek candies for Maomao, Dudu comes to a maze. There are nn rooms numbered from 11 to nn and mm undirected roads.

There are two kinds of rooms in the maze -- candy room and monster room. There is one candy in each candy room, and candy room is safe. Dudu can take the only candy away when entering the room. After he took the candy, this candy room will be empty. A empty room is also safe. If Dudu is in safe, he can choose any one of adjacent rooms to go, whatever it is. Two rooms are adjacent means that at least one road connects the two rooms.

In another kind of rooms, there are fierce monsters. Dudu can't beat these monsters, but he has a magic portal. The portal can show him a randomly chosen road which connects the current room and the other room.

The chosen road is in the map so Dudu know where it leads to. Dudu can leave along the way to the other room, and those monsters will not follow him. He can only use the portal once because the magic energy is not enough.

Dudu can leave the maze whenever he wants. That's to say, if he enters a monster room but he doesn't have enough energy to use the magic portal, he will choose to leave the maze immediately so that he can save the candies he have. If he leave the maze, the maze will never let him in again. If he try to fight with the monsters, he will be thrown out of the maze (never let in, of course). He remembers the map of the maze, and he is a clever guy who can move wisely to maximum the expection of candies he collected.

Maomao wants to know the expected value of candies Dudu will bring back. Please tell her the answer. He will start his adventure in room 1, and the room 1 is always a candy room. Since there may be more than one road connect the current room and the room he wants to go to, he can choose any of the roads.

思路:

将所有连起来的点并且中间没有怪物的点连起来, 1的联通必选, 在从1能到的怪物的点挨个枚举, 选一个期望最大的点即可.

代码:

#include <bits/stdc++.h>
using namespace std; const int MAXN = 1e5+10;
vector<int> G[MAXN];
int Fa[MAXN], Sum[MAXN];
bool Vis[MAXN];
int n, m, k; int GetF(int x)
{
if (Fa[x] == x)
return x;
Fa[x] = GetF(Fa[x]);
return Fa[x];
} int main()
{
int t;
scanf("%d", &t);
while (t--)
{
scanf("%d%d%d", &n, &m, &k);
for (int i = 1;i <= n;i++)
Fa[i] = i, Sum[i] = 1, Vis[i] = false, G[i].clear();
int u, v;
for (int i = 1;i <= m;i++)
{
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
for (int i = 1;i <= k;i++)
{
scanf("%d", &u);
Vis[u] = true;
Sum[u] = 0;
}
for (int i = 1;i <= n;i++)
{
for (int j = 0;j < G[i].size();j++)
{
int a = i, b = G[i][j];
if (Vis[a] || Vis[b])
continue;
a = GetF(a);
b = GetF(b);
if (a != b)
{
if (a == 1)
{
Fa[b] = a;
Sum[a] += Sum[b];
}
else
{
Fa[a] = b;
Sum[b] += Sum[a];
}
}
}
}
double res = 0;
for (int i = 1;i <= n;i++)
{
if (!Vis[i])
continue;
bool Flag = false;
for (int j = 0;j < G[i].size();j++)
{
if (GetF(G[i][j]) == 1)
{
Flag = true;
break;
}
}
if (!Flag)
continue;
double tmp = 0;
for (int j = 0;j < G[i].size();j++)
{
int node = GetF(G[i][j]);
if (node != 1)
{
// cout << Sum[node] << ' ' << G[i].size() << endl;
tmp += (Sum[node]*1.0)/(int)G[i].size();
}
}
res = max(res, tmp);
}
res += Sum[1];
printf("%.6lf\n", res);
} return 0;
}

2019ICPC沈阳网络赛-B-Dudu's maze(缩点)的更多相关文章

  1. 2019沈阳网络赛B.Dudu's maze

    https://www.cnblogs.com/31415926535x/p/11520088.html 啊,,不在状态啊,,自闭一下午,,都错题,,然后背锅,,,明明这个简单的题,,, 这题题面不容 ...

  2. 2019icpc沈阳网络赛 D Fish eating fruit 树形dp

    题意 分别算一个树中所有简单路径长度模3为0,1,2的距离和乘2. 分析 记录两个数组, \(dp[i][k]\)为距i模3为k的子节点到i的距离和 \(f[i][k]\)为距i模3为k的子节点的个数 ...

  3. 2019ICPC沈阳网络赛-D-Fish eating fruit(树上DP, 换根, 点分治)

    链接: https://nanti.jisuanke.com/t/41403 题意: State Z is a underwater kingdom of the Atlantic Ocean. Th ...

  4. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  5. 线段树+单调栈+前缀和--2019icpc南昌网络赛I

    线段树+单调栈+前缀和--2019icpc南昌网络赛I Alice has a magic array. She suggests that the value of a interval is eq ...

  6. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

  7. 沈阳网络赛 F - 上下界网络流

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

  8. 沈阳网络赛J-Ka Chang【分块】【树状数组】【dfs序】

    Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, ...

  9. 沈阳网络赛D-Made In Heaven【k短路】【模板】

    One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci ...

随机推荐

  1. python copy与deepcopy (拷贝与深拷贝)

    copy与deepcopy python 中的copy与deepcopy是内存数据的操作,但是两个函数有一定的区别. 1.copy import copy list = [1, [4, 5, 6], ...

  2. vue-teach

    编译器的工作过程 http://www.ruanyifeng.com/blog/2014/11/compiler.html DNS 原理入门 http://www.ruanyifeng.com/blo ...

  3. hue改保存记录条数

    参考: https://blog.csdn.net/liaoxiaoyi121121/article/details/80541901 需求: 开发需要保存查询记录的条数从10万改到100万 /etc ...

  4. 将PostgreSQL数据库的表导入到elasticsearch中

    1.查看PostgreSQL表结构和数据信息 edbstore=# \d customers Table "edbstore.customers" Column | Type | ...

  5. PTA(Advanced Level)1046.Shortest Distance

    The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...

  6. Python中的逻辑运算符

  7. Configure脚本支持说明

    在Linux上安装Nginx需要执行Configure脚本,该脚本需要做一些参数说明: 选项 说明 --prefix=<path> 指定Nginx软件的安装路径,若不指定默认安装在/usr ...

  8. HDU 3416 Marriage Match IV (最短路建图+最大流)

    (点击此处查看原题) 题目分析 题意:给出一个有n个结点,m条单向边的有向图,问从源点s到汇点t的不重合的最短路有多少条,所谓不重复,意思是任意两条最短路径都不共用一条边,而且任意两点之间的边只会用一 ...

  9. 首探:Ruby on Rails 简单了解

    一. 安装 Ruby安装:https://ruby-china.org/wiki/rvm-guide 注:安装了RVM和Gem后 安装rails: gem install rails -v 5.1.4 ...

  10. Java重要类之LinkedList

    一.ArrayList与LinkedList 基本概念:List是一个接口,Arraylist和LinkedList是它的两个实现类,只是实现的方式不一样.我在“单链表java实现”一文中已经对单链表 ...