链接:

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. PI膜应变片试样制备

    一.选取基板 1.喷涂在玻璃基板上PI膜 2.正面用记号笔标记PI膜工艺参数——转速.厚度 3.玻璃板背面为PI膜 二.贴防护膜 1.事先画好二维图,以dxf格式存放 2.裁减合适的大小,并将其贴在打 ...

  2. 【坑】不要使用各种框架提供的内部List

    为了代码简洁有时我们会使用一些框架提供的工具类.如 import org.apache.commons.collections.ListUtils; package java.util.Collect ...

  3. Oracle 获取当前日期是月的第几周

    函数FUNC_GET_WEEKOFMONTH: IW 是年的自然周: WW是年的第一天起开始算7天为一周 FUNCTION FUNC_GET_WEEKOFMONTH (V_PSD DATE) RETU ...

  4. Sublime Text 3 注册激活码

    Sublime Text 3 注册激活码 ----- BEGIN LICENSE ----- sgbteam Single User License EA7E-1153259 8891CBB9 F15 ...

  5. 链表-简单练习题1-数据结构实验之链表一:顺序建立链表 SDUT2117

    Problem Description 输入N个整数,按照输入的顺序建立单链表存储,并遍历所建立的单链表,输出这些数据. Input 第一行输入整数的个数N:第二行依次输入每个整数. Output 输 ...

  6. Vue的快速入门

    1 环境准备 1 下载安装Node 地址https://nodejs.org/en/download/ 完成后通过cmd打开控制台输入node -v 可以看到版本信息 2 通过该node自带的npm ...

  7. Java8 parallelStream浅析

    JAVA8中引入了lamda表达式和Stream接口.其丰富的API及强大的表达能力极大的简化代码,提升了效率,同时还通过parallelStream提供并发操作的支持,本文探讨parallelStr ...

  8. Scala学习一——基础

    一.使用Scala解释器 如果以命令行的方式运行,输出的结果会把类型带上,且结果名默认为res0递增.且Scala解释器读到一个解释器求值打印然后读取下一个(这个过程为读取-求值-打印-循环[REPL ...

  9. ArrayList扩容分析

    一段java代码 String e = "q3234v"; List<String> list = new ArrayList<String>(); for ...

  10. 分布式---CAP和BASE理论

    3.CAP   分布式系统不可能同时满足一致性(C:Consistence),可用性(A:Avaliability)和分区容忍性(P:Partition Tolerance),最多只能同时满足其中的两 ...