当前位置:网站首页>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
边栏推荐
- Deep learning notes - semantic segmentation and data sets
- Unity C# 网络学习(四)
- Various ways of writing timed tasks of small programs
- 机器学习---线性回归
- API slow interface analysis
- C. Tree infection (simulation + greed)
- Innovation training (V) mid term inspection
- The 2021 more reading report was released, and the book consumption potential of post-95 and Post-00 rose
- MySQL memo (for your own query)
- 5 minutes to understand MySQL row column conversion
猜你喜欢
What are the redis data types
Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
Use model load_ state_ Attributeerror appears when dict(): 'STR' object has no attribute 'copy‘
COM in wine (2) -- basic code analysis
Live delivery form template - automatically display pictures - automatically associate series products
MySQL -- execution process and principle of a statement
AQS source code reading
多线程基本概念(并发与并行、线程与进程)和入门案例
#define 定义常量和宏,指针和结构体
Thoughts on a small program
随机推荐
AQS source code reading
Perfect test of coil in wireless charging system with LCR meter
The WebService interface writes and publishes calls to the WebService interface (I)
Docker installation and mysql5 7 installation
Learning Android from scratch -- Introduction
【数据库】MySQL单表查询
Basic concepts of multithreading (concurrency and parallelism, threads and processes) and entry cases
2022/4/22
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
MySQL -- execution process and principle of a statement
Solve valueerror: argument must be a deny tensor: 0 - got shape [198602], but wanted [198602, 16]
Some experience in using MySQL / tidb database [slowly updating...]
Use AES encryption - reuse the wisdom of predecessors
Nacos source code startup error report solution
Leetcode -- heuristic search
JS determines whether the numeric string contains characters
跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
Sword finger offer: push in and pop-up sequence of stack
深度学习笔记 —— 语义分割和数据集
Using MySQL with Oracle