当前位置:网站首页>Simple application of parallel search set (red alarm)
Simple application of parallel search set (red alarm)
2022-04-23 05:08:00 【FOWng_ lp】
https://pintia.cn/problem-sets/994805046380707840/problems/994805063963230208
Ideas
The meaning of this code is to divide the graph into blocks , The nodes that can go through are merged into a set , The total number of blocks is num1. Then remove a node , Block again , The total number of blocks is num2. If num2-1( Remove a single node ) And num1 Equal or num2( After removing this node , The block where the node is located is still interconnected ) be equal to num1, Connectivity is not affected .
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int father[550],road[5005][5],over,vis[5005],check[5005];
int find(int x){
while(father[x]!=x){
x=father[x];
}
return x;
}
void conbine(int x,int y){
if(find(x)!=find(y)){
father[find(x)]=find(y);
}
}
int main(){
int n,m,k,a,b;
cin >> n >>m;
for(int i = 0;i <= n;i++){
father[i] = i;
}
for(int i = 1;i <= m;i++){
cin >> a >> b;
road[i][1] = a;
road[i][2] = b;
conbine(a,b);
}
int num1 = 0;
for(int i = 0;i < n;i++){
if(father[i]==i)num1++;
}
cin >> k;
// Yes K To deal with
for(int i = 1;i<= k;i++){
int num2 = 0;
cin >> a;
check[a]=1;
if(over)continue;
for(int j = 0;j<n;j++){
father[j]=j;
}
for(int j = 1;j <= m;j++){
if(road[j][1]==a||road[j][2]==a||vis[j]){
vis[j]=1;
continue;
}
conbine(road[j][1],road[j][2]);
}
for(int j = 0;j < n;j++){
if(j==father[j])num2++;
}
//cout<< num1 << " " << num2 <<endl;
if(num1==num2-1||num1==num2){
printf("City %d is lost.\n",a);
}
else if(num2-1 > num1){
printf("Red Alert: City %d is lost!\n",a);
}
num1 = num2;
over = 1;
for(int j = 0;j < n;j++){
if(!check[j])over = 0;
}
if(over)puts("Game Over.");
}
return 0;
}
版权声明
本文为[FOWng_ lp]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220549345434.html
边栏推荐
- Servlet3 0 + event driven for high performance long polling
- MySQL slow query
- Thoughts on a small program
- Redis data type usage scenario
- scp命令详解
- JS engine loop mechanism: synchronous, asynchronous, event loop
- L2-011 play binary tree (build tree + BFS)
- Unity C# 网络学习(四)
- Detailed explanation of concurrent topics
- Chapter III project schedule management of information system project manager summary
猜你喜欢
Servlet3 0 + event driven for high performance long polling
直播带货表格模板-自动显示图片-自动关联系列商品
Learning Android II from scratch - activity
使用zerotier让异地设备组局域网
DIY is an excel version of subnet calculator
[2021] Spatio-Temporal Graph Contrastive Learning
Sword finger offer: the path with a certain value in the binary tree (backtracking)
Learning Android from scratch -- Introduction
Deep learning notes - data expansion
独立站运营 | FaceBook营销神器——聊天机器人ManyChat
随机推荐
JS détermine si la chaîne de nombres contient des caractères
What are instruction cycles, machine cycles, and clock cycles?
Sword finger offer: push in and pop-up sequence of stack
#define 定义常量和宏,指针和结构体
Logrus set log format and output function name
The 2021 more reading report was released, and the book consumption potential of post-95 and Post-00 rose
2022/4/22
Repair of self calibration SPC failure of Tektronix oscilloscope dpo3054
Innovation training (XI) airline ticket crawling company information
TypeError: ‘Collection‘ object is not callable. If you meant to call the ......
MySQL foreign key constraint
MySQL uses or to query SQL, and SQL execution is very slow
JS determines whether the numeric string contains characters
Detailed explanation of concurrent topics
Solve valueerror: argument must be a deny tensor: 0 - got shape [198602], but wanted [198602, 16]
Redis data type usage scenario
信息学奥赛一本通 1212:LETTERS | OpenJudge 2.5 156:LETTERS
2022/4/22
The vscode ipynb file does not have code highlighting and code completion solutions
信息学奥赛一本通 1955:【11NOIP普及组】瑞士轮 | OpenJudge 4.1 4363:瑞士轮 | 洛谷 P1309 [NOIP2011 普及组] 瑞士轮