UVALive Problem 7456 Least Crucial Node——Regionals 2015 :: Asia - Taipei
2016-08-29 22:19
441 查看
此文章可以使用目录功能哟↑(点击上方[+])
Accept: 0 Submit: 0
Time Limit: 3.000 seconds
A wireless sensor network is a self-organizing network without specific infrastructure. It is a multi-hop network in which sensor nodes can be randomly deployed and the data transmission between nodes usually involves other intermediate
nodes. Sensor nodes are often deployed in outdoor or hazardous environments. Power outage of sensors can lead to node failure and cause many serious problem. For example, node failure can disconnect the whole network, causing data from one part of the network
to fail to transmit to another part of the network. It is difficult to replace failed sensor nodes in hazardous conditions or far-reaching areas such as rainforests or high mountains.
Wireless sensor networks usually connect to the outside world through the so called sinks (may be regarded as gateways). All data collected by sensor nodes are sent to the sink, and then the sink relays such data to remote users or
servers through the Internet, satellite, or any viable medium.
A wireless sensor network can be modeled by a graph with each vertex (edge) representing a sensor (a two-way communication link). In the following figure, nodes 4, 10, and 14 are more crucial to the connectivity of the network since
a power shortage in any one of them can lead to a disconnected network.
Suppose that node 1 is the sink node. The failure of node 4 disconnects nodes in the set {5, 6, 7, 8, 9, 10, 11, 12, 13, 14} from the sink. The failure of node 10 disconnects the nodes in the set {11, 12, 13, 14} from the sink. Lastly,
the failure of node 14 disconnects the nodes in {12, 13} from the sink. This means node 4 is more crucial than nodes 10 and 14 in network connectivity; thus we call node 4 a crucial node of the network. Notice that crucial nodes do not include the sink. Specifically,
the failure of a crucial node in a given sensor network disconnects the largest number of nodes from the sink. Moreover, the least crucial node is a crucial node with the least number label among all the crucial nodes.
Please write a program to find the least crucial node for a given sensor network with a specific sink.
There are several input lines to a test case. The first line of each test case contains an integer n (2 ≤ n ≤ 100), where n is the number of nodes (vertex set of G) labeled with {1, 2, . . . , n} in the network. The second line contains an integer, which
is the label of the unique sink of the network. The third line contains an integer m, indicating the number of communication links in the network. The next m lines each contains a pair of integers, say i and j (separated by a space), denoting there is a communication
link (edge in E) between node i and node j. There are at most 10 test cases and n = 0 denotes end of the test cases.
The output for each instance should contain an integer denoting the least crucial node in the given network.
4
4
3
1 2
2 3
3 4
6
3
8
1 2
2 3
2 4
2 5
3 4
3 5
4 5
5 6
0
3
2
解题思路:
【题意】
n个结点,m条双向边
问对于点k,剩下的n-1个结点中最至关重要的点是哪个点
对于最至关重要的点的定义:删除该点之后会使得能与点k连通的点的个数最少
若有多个符合条件的点,取标号最小的
【类型】
暴力枚举+并查集
【分析】
因为n的大小范围为2 ≤ n ≤ 100,显然可以暴力枚举每个点
看删除该点之后仍与k连通的结点有多少个,取最小的那个即可
而判断与k是否连通,可以通过并查集实现,与点k在一个集合中说明与点k连通
如样例二
由上可知,删除结点2或结点5时,剩下的点与点3连通的都只有3个,那么点2和点5都是最至关重要的点
此时需选取标号最小的结点,于是点2就是最终结果
【时间复杂度&&优化】
O(nmlogn)
题目链接→UVALive
Problem 7456 Least Crucial Node
/*Sherlock and Watson and Adler*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-9
#define LL long long
#define PI acos(-1.0)
#define bitnum(a) __builtin_popcount(a)
using namespace std;
const int N = 105;
const int M = 100005;
const int inf = 1000000007;
const int mod = 1000000007;
int s
,u[M],v[M];
int fun(int x)
{
if(s[x]!=x)
s[x]=fun(s[x]);
return s[x];
}
int main()
{
int n,k,m,i,j,ans,c,t,Min;
while(scanf("%d",&n)&&n)
{
Min=inf;
scanf("%d",&k);
scanf("%d",&m);
for(i=0;i<m;i++)
scanf("%d%d",&u[i],&v[i]);
for(i=1;i<=n;i++)
{
if(i==k)
continue;
for(j=1;j<=n;j++)
s[j]=j;
for(j=0;j<m;j++)
if(u[j]!=i&&v[j]!=i)
s[fun(u[j])]=fun(v[j]);
c=fun(k);t=0;
for(j=1;j<=n;j++)
if(fun(j)==c)
t++;
if(t<Min)
Min=t,ans=i;
}
printf("%d\n",ans);
}
return 0;
}
菜鸟成长记
UVALive Problem 7456 Least Crucial Node
Accept: 0 Submit: 0Time Limit: 3.000 seconds
Problem Description
A wireless sensor network is a self-organizing network without specific infrastructure. It is a multi-hop network in which sensor nodes can be randomly deployed and the data transmission between nodes usually involves other intermediatenodes. Sensor nodes are often deployed in outdoor or hazardous environments. Power outage of sensors can lead to node failure and cause many serious problem. For example, node failure can disconnect the whole network, causing data from one part of the network
to fail to transmit to another part of the network. It is difficult to replace failed sensor nodes in hazardous conditions or far-reaching areas such as rainforests or high mountains.
Wireless sensor networks usually connect to the outside world through the so called sinks (may be regarded as gateways). All data collected by sensor nodes are sent to the sink, and then the sink relays such data to remote users or
servers through the Internet, satellite, or any viable medium.
A wireless sensor network can be modeled by a graph with each vertex (edge) representing a sensor (a two-way communication link). In the following figure, nodes 4, 10, and 14 are more crucial to the connectivity of the network since
a power shortage in any one of them can lead to a disconnected network.
Suppose that node 1 is the sink node. The failure of node 4 disconnects nodes in the set {5, 6, 7, 8, 9, 10, 11, 12, 13, 14} from the sink. The failure of node 10 disconnects the nodes in the set {11, 12, 13, 14} from the sink. Lastly,
the failure of node 14 disconnects the nodes in {12, 13} from the sink. This means node 4 is more crucial than nodes 10 and 14 in network connectivity; thus we call node 4 a crucial node of the network. Notice that crucial nodes do not include the sink. Specifically,
the failure of a crucial node in a given sensor network disconnects the largest number of nodes from the sink. Moreover, the least crucial node is a crucial node with the least number label among all the crucial nodes.
Please write a program to find the least crucial node for a given sensor network with a specific sink.
Input
There are several input lines to a test case. The first line of each test case contains an integer n (2 ≤ n ≤ 100), where n is the number of nodes (vertex set of G) labeled with {1, 2, . . . , n} in the network. The second line contains an integer, whichis the label of the unique sink of the network. The third line contains an integer m, indicating the number of communication links in the network. The next m lines each contains a pair of integers, say i and j (separated by a space), denoting there is a communication
link (edge in E) between node i and node j. There are at most 10 test cases and n = 0 denotes end of the test cases.
Output
The output for each instance should contain an integer denoting the least crucial node in the given network.
Sample Input
44
3
1 2
2 3
3 4
6
3
8
1 2
2 3
2 4
2 5
3 4
3 5
4 5
5 6
0
Sample Output
32
Problem Idea
解题思路:【题意】
n个结点,m条双向边
问对于点k,剩下的n-1个结点中最至关重要的点是哪个点
对于最至关重要的点的定义:删除该点之后会使得能与点k连通的点的个数最少
若有多个符合条件的点,取标号最小的
【类型】
暴力枚举+并查集
【分析】
因为n的大小范围为2 ≤ n ≤ 100,显然可以暴力枚举每个点
看删除该点之后仍与k连通的结点有多少个,取最小的那个即可
而判断与k是否连通,可以通过并查集实现,与点k在一个集合中说明与点k连通
如样例二
由上可知,删除结点2或结点5时,剩下的点与点3连通的都只有3个,那么点2和点5都是最至关重要的点
此时需选取标号最小的结点,于是点2就是最终结果
【时间复杂度&&优化】
O(nmlogn)
题目链接→UVALive
Problem 7456 Least Crucial Node
Source Code
/*Sherlock and Watson and Adler*/#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>
#include<iostream>
#define eps 1e-9
#define LL long long
#define PI acos(-1.0)
#define bitnum(a) __builtin_popcount(a)
using namespace std;
const int N = 105;
const int M = 100005;
const int inf = 1000000007;
const int mod = 1000000007;
int s
,u[M],v[M];
int fun(int x)
{
if(s[x]!=x)
s[x]=fun(s[x]);
return s[x];
}
int main()
{
int n,k,m,i,j,ans,c,t,Min;
while(scanf("%d",&n)&&n)
{
Min=inf;
scanf("%d",&k);
scanf("%d",&m);
for(i=0;i<m;i++)
scanf("%d%d",&u[i],&v[i]);
for(i=1;i<=n;i++)
{
if(i==k)
continue;
for(j=1;j<=n;j++)
s[j]=j;
for(j=0;j<m;j++)
if(u[j]!=i&&v[j]!=i)
s[fun(u[j])]=fun(v[j]);
c=fun(k);t=0;
for(j=1;j<=n;j++)
if(fun(j)==c)
t++;
if(t<Min)
Min=t,ans=i;
}
printf("%d\n",ans);
}
return 0;
}
菜鸟成长记
相关文章推荐
- UVALive Problem 7454 Parentheses——Regionals 2015 :: Asia - Taipei
- UVALive Problem 7457 Discrete Logarithm Problem——Regionals 2015 :: Asia - Taipei
- Regionals 2015 :: Asia - Taipei C - Least Crucial Node 割点应用
- Least Crucial Node UVALive - 7456 【】
- UVALive 7456 Least Crucial Node
- UVaLive 7456 Least Crucial Node (并查集+暴力 或者 求割点)
- 【割点 && dfs】UVALive - 7456 Least Crucial Node
- UVALive 7456 Least Crucial Node (并查集)
- Uvalive 4267 Finding The Heaviest Path (Regionals 2008 Asia Taipei +DFS结点最大权值路径)
- UVALive 4260 Fortune Card Game (Regionals 2008 Asia Taipei +DP)
- UVALive 4264 Message(Regionals 2008 :: Asia - Taipei+模拟)
- Regionals 2009 :: Asia - Hsinchu UVALIVE, 4527 Vaccination Centers - 搜索剪枝
- Regionals 2009 >> Asia - Hsinchu UVALIVE, 4528 Schedule Pairs of Jobs - 搜索回溯
- Regionals 2009 >> Asia - Hsinchu UVALIVE, 4529 A Constrained Queen Game - 搜索剪枝
- Regionals 2015 :: Asia - Taipei 部分题解
- UVALive 7147 World Cup(2014 Regionals 2014 :: Asia - ShangHai)
- Regionals 2015 Asia - Daejeon acmliveoj7233 - Polynomial
- Regionals 2009 Asia - Hsinchu UVALIVE, 4525 - Clues 搜索
- LA 7456 Least Crucial Node
- Regionals 2007 >> Asia - Nanjing - "Ray, Pass me the dishes!" 线段树 难 uva live 3938