当前位置:网站首页>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
边栏推荐
- Installing kuberneters using kubedm
- Deep learning notes - data expansion
- Perfect test of coil in wireless charging system with LCR meter
- Knowledge points sorting: ES6
- Implementation of switching windows and capturing data in selenium mode
- Sword finger offer: push in and pop-up sequence of stack
- How to exit VIM
- QPushbutton 槽函数被多次触发
- 静态流水线和动态流水线的区别认识
- What are the redis data types
猜你喜欢

【数据库】MySQL多表查询(一)

深度学习笔记 —— 数据增广

MySQL memo (for your own query)

MySQL foreign key constraint

Repair of self calibration SPC failure of Tektronix oscilloscope dpo3054

《2021多多阅读报告》发布,95后、00后图书消费潜力攀升

One month countdown, pgconf What are the highlights of the latest outlook of asia2021 Asian Conference?

Learning Android V from scratch - UI

跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?

Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
随机推荐
Mac 进入mysql终端命令
Get the number of days between dates, get the Chinese date, get the date of the next Monday of the date, get the working day, get the rest day
Innovation training (V) mid term inspection
JS détermine si la chaîne de nombres contient des caractères
Analysis of POM files
What are the redis data types
Use AES encryption - reuse the wisdom of predecessors
Cross border e-commerce | Facebook and instagram: which social media is more suitable for you?
Leetcode -- heuristic search
Basic concepts of multithreading (concurrency and parallelism, threads and processes) and entry cases
Detailed explanation of concurrent topics
【数据库】MySQL基本操作(基操~)
The vscode ipynb file does not have code highlighting and code completion solutions
Streamexecutionenvironment of Flink source code
Introduction to load balancing
API slow interface analysis
C. Tree infection (simulation + greed)
跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
Deep learning notes - fine tuning
[winui3] Écrivez une copie du gestionnaire de fichiers Explorer