当前位置:网站首页>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;
}边栏推荐
- Brief introduction of 228 dropout methods of pytorch and fast implementation of dropblock with 4 lines of code based on dropout
- 栈溢出漏洞
- docker部署redis集群
- Flink學習2:應用場景
- Oracle/PLSQL: CharToRowid Function
- XSS attack (note)
- How does the C # TCP server limit the number of connections to the same IP?
- 2022年氯碱电解工艺试题及答案
- TP5 Spreadsheet Excle 表格导出
- 学习太极创客 — MQTT 第二章(三)保留消息
猜你喜欢
![[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](/img/e4/7bae2a109dcf5e2a8f032e73b89479.png)
[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

流沙画模拟器源码

QIngScan使用

【微服务|Sentinel】降级规则|慢调用比例|异常比例|异常数

Flink学习2:应用场景

Yiwen teaches you Kali information collection

Super détaillé, 20 000 caractères détaillés, mangez à travers es!

Flink learning 1: Introduction

Cvpr2022 | pointdistiller: structured knowledge distillation for efficient and compact 3D detection

超级详细,2 万字详解,吃透 ES!
随机推荐
Laravel 的 ORM 缓存包
参数估计——《概率论及其数理统计》第七章学习报告(点估计)
Test the respective roles of nohup and &
Summer planning for the long river
2022茶艺师(高级)上岗证题库模拟考试平台操作
Flink学习2:应用场景
"All majors are persuading them to quit." is it actually the most friendly to college students?
PAT甲级 1025 PAT Ranking
XSS attack (note)
学习太极创客 — MQTT(七)MQTT 主题进阶
Learn from Taiji Maker - mqtt Chapter 2 (I) QoS service quality level
Oracle/PLSQL: To_ Clob Function
TechSmith Camtasia latest 2022 detailed function explanation Download
PAT甲级 1019 General Palindromic Number
2022中式面点师(高级)复训题库及在线模拟考试
paddlepaddle 21 基于dropout实现用4行代码dropblock
How do I simplify the development of interfaces in open source systems?
Paddlepaddle 20 implementation and use of exponentialmovingaverage (EMA) (support static graph and dynamic graph)
Flink学习3:数据处理模式(流批处理)
Enterprise digital transformation: informatization and digitalization
https://github.com/ZouJiu1/PAT