当前位置:网站首页>Pat grade a 1021 deep root
Pat grade a 1021 deep root
2022-06-27 02:51:00 【IX. non random address】
And query the set to view the trees of the tree ; Dijie Tesla way to find the farthest path
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<bits/stdc++.h>
using namespace std;
int finder(int *unionfind, int x){
while(x!=unionfind[x]) x = unionfind[x];
return x;
}
void unioner(int *unionfind, int x, int y){
int a = finder(unionfind, x);
int c = finder(unionfind, y);
if(a > c)
unionfind[y] = unionfind[x] = c;
else
unionfind[y] = unionfind[x] = a;
}
int main(void){
int m, n, a, b, c, d, e, f;
int INFINF = -999999;
cin>>n;
f = n + 1;
int matrix[f][f];
int unionsz[f]; // And look up the set to see the number of trees
for(int i=0; i<f; i++) unionsz[i] = i;
memset((void *)matrix, INFINF, sizeof(int) * f * f);
for(int i = 0; i < (n - 1); i++){
cin>>a>>b;
matrix[b][a] = matrix[a][b] = 1;
unioner(unionsz, a, b);
}
e = 0;
for(int i = 1; i < f; i++){
if(unionsz[i]==i) e++;
}
if(e!=1){
printf("Error: %d components", e);
return 0;
}
int maxdis[f][f];
int visited[f][f];
memset((void *)visited, 0, sizeof(int) * f * f);
memset((void *)maxdis, INFINF, sizeof(int) * f * f);
int maxval;
for(c = 1; c < f; c++){ // Dijietesla mode
for(int i = 0; i < f; i++){
maxval = -9999999;
maxdis[c][c] = 0;
m = 0;
for(int j = 0; j < f; j++){
if(maxdis[c][j] > maxval && visited[c][j]==0){
maxval = maxdis[c][j];
m = j;
}
}
visited[c][m] = 1;
for(int j = 0; j < f; j++){
if((maxval + matrix[m][j]) > maxdis[c][j] && visited[c][j]==0){
maxdis[c][j] = maxval + matrix[m][j];
}
}
}
}
maxval = -999999;
for(int i = 0; i < f; i++){
for(int j = 0; j < f; j++){
if(maxdis[i][j] > maxval){
maxval = maxdis[i][j];
}
}
}
vector<int> vr;
for(int i = 0; i < f; i++){
for(int j = 0; j < f; j++){
if(maxdis[i][j] == maxval){
vr.push_back(j);
}
}
}
vr.push_back(999999);
sort(vr.begin(), vr.end());
for(int i = 0; i < vr.size() - 1; i++){
if(vr[i+1]==vr[i]) continue;
else cout<<vr[i]<<endl;
}
return 0;
}边栏推荐
- Calculation of average wind direction and speed (unit vector method)
- Learn Tai Chi Maker - mqtt (VIII) esp8266 subscribe to mqtt topic
- Sample development of WiFi IOT Hongmeng development kit
- lottie. JS creative switch button animal head
- docker部署redis集群
- Learning Tai Chi Maker - mqtt Chapter 2 (II) esp8266 QoS application
- Topolvm: kubernetes local persistence scheme based on LVM, capacity aware, dynamically create PV, and easily use local disk
- Laravel 的 ORM 缓存包
- 455. distribute biscuits [distribution questions]
- Flink学习5:工作原理
猜你喜欢

Record the method of reading excel provided by unity and the solution to some pits encountered

学习太极创客 — MQTT 第二章(三)保留消息

PAT甲级 1021 Deepest Root
![[Shangshui Shuo series] day 6](/img/47/7cd44f4e361af53cac7cea9d0d7ecb.png)
[Shangshui Shuo series] day 6

"All majors are persuading them to quit." is it actually the most friendly to college students?

1. Project preparation and creation

解决cherry pick提交报错问题

What if asreml-r does not converge in operation?

Flink学习1:简介

Flink learning 5: how it works
随机推荐
达梦数据库的卸载
Detailed explanation of ThreadLocal
[array] sword finger offer II 012 The sum of left and right subarrays is equal | sword finger offer II 013 Sum of two dimensional submatrix
Oracle/PLSQL: NumToYMInterval Function
PAT甲级 1018 Public Bike Management
Press key to control LED status reversal
PAT甲级 1023 Have Fun with Numbers
参数估计——《概率论及其数理统计》第七章学习报告(点估计)
How does the C # TCP server limit the number of connections to the same IP?
Brief introduction of 228 dropout methods of pytorch and fast implementation of dropblock with 4 lines of code based on dropout
Google began to roll itself, AI architecture pathways was blessed, and 20billion generation models were launched
Getting started with bluecms code auditing
C language -- Design of employee information management system
Oracle/PLSQL: To_ Clob Function
lodash get js代码实现
人群模拟
pytorch_ grad_ Cam -- visual Library of class activation mapping (CAM) under pytorch
Microsoft365开发人员申请
Introduction to stm32
[Shangshui Shuo series] day 6
https://github.com/ZouJiu1/PAT