当前位置: 首页 > news >正文

股票实时交易网站开发百度登录个人中心官网

股票实时交易网站开发,百度登录个人中心官网,网站建设常州,网站备案跟域名有什么关系题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id1681 题目大意:给你一共有n个结点但是不连通的无向图,你需要用最少的线将其变成连通图,并使连通图中两个的点最长距离最小(一个点可以连接多条线&#xf…

题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1681

题目大意:给你一共有n个结点但是不连通的无向图,你需要用最少的线将其变成连通图,并使连通图中两个的点最长距离最小(一个点可以连接多条线)。

解题思路:最后肯定是将每个图的最长线段的中点连接起来。所以我们要找最长距离,就是找到两个线段最长的图,输出它们线段长度除2相加再加1的结果,特别注意如果拥有最长线段长度的图有三个,那么最后不是加1,而是加二。
求一个图中最长线段长度两遍dfs即可,第一遍找到最长线段的一个端点,第二遍根据找到的端点再dfs一次即可得到最长的线段长度。


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#define RI(N) scanf("%d",&(N))
#define RII(N,M) scanf("%d %d",&(N),&(M))
#define RIII(N,M,K) scanf("%d %d %d",&(N),&(M),&(K))
#define Cl0(a) memset((a),0,sizeof(a))
using namespace std;
const int inf=1e9;
const int inf1=-1*1e9;
typedef long long LL;
vector <int> g [100005];bool used[100005];
bool used1[100005];
int ans[100005];
int maxx,maxxx;int dfs(int p,int ans)
{used[p]=1;used1[p]=1;int length=g[p].size();int i=0;for(; i<length; i++){if(!used1[g[p][i]]){dfs(g[p][i],ans+1);}}if(ans>maxx){maxx=ans;maxxx=p;}return maxxx;
}int dfs1(int p,int ans)
{used1[p]=1;int length=g[p].size();int i=0;for(; i<length; i++){if(!used1[g[p][i]]){dfs1(g[p][i],ans+1);}}if(ans>maxx)  maxx=ans;return maxx;
}int main()
{int c,l,num=0;while(RII(c,l)!=EOF){memset(used,0,sizeof(used));for(int i=0; i<l; i++){int x,y;RII(x,y);g[x].push_back(y);g[y].push_back(x);}for(int i=0; i<c; i++){if(!used[i]){memset(used1,0,sizeof(used1));maxx=-1;int v=dfs(i,0);memset(used1,0,sizeof(used1));maxx=-1;ans[num++]=dfs1(v,0);}}sort(ans,ans+num);int ans1=ans[num-1];int ans2=0,ans3=0;if(num>=3){if(ans[num-1]==ans[num-2]&&ans[num-2]==ans[num-3])ans2=(ans[num-1]+1)/2*2+2;else ans2=(ans[num-1]+1)/2+(ans[num-2]+1)/2+1;}if(num==2) ans2=(ans[num-1]+1)/2+(ans[num-2]+1)/2+1;cout<<max(ans1,ans2)<<endl;for(int i=0;i<c;i++)g[i].clear();}return  0;
}
http://www.lbrq.cn/news/2417221.html

相关文章:

  • 网站开发网站建设公司seo搜索引擎排名优化
  • 手机网站样式代码微信营销软件免费版
  • 濮阳网站建设广州网站推广平台
  • 中国新闻社是什么级别萧山区seo关键词排名
  • 网站营销的分类有哪些seo网站排名优化软件是什么
  • 安徽省级建设主管部门网站搜索引擎营销特点
  • 郑州有做彩票网站的吗企业网站推广方法实验报告
  • 深圳微信网站公司哪家好现在有什么技能培训班
  • 上海网站推广模板seo网页优化工具
  • 武汉网站推广服务百度小程序seo
  • 大鹏网络网站建设报价守游网络推广平台
  • seo短视频网页入口引流网站推荐网站建设方案模板
  • 网站公司建设台州seo排名公司
  • 高端网站建设专业网站如何做seo推广
  • 告状书放网站上怎么做什么是网络营销工具
  • 上海网站建设开发公司seo综合查询工具下载
  • 文山做网站安卓优化大师最新版下载
  • 西宁公安网站建设四川成都最新消息
  • 建站的注意事项官网站内推广内容
  • 万网网站备案流程十大计算机培训学校
  • 自己做链接的网站吗提高工作效率的措施
  • 宁波做网站的网页seo搜索引擎优化
  • 网站如何做等保备案临沂今日头条新闻最新
  • wordpress b站插件市场调研方案范文
  • 广州网站seo上海关键词优化的技巧
  • 个人网站建设分几个步走百度站长平台官网登录入口
  • 大埔建设工程交易中心网站湖南长沙最新情况
  • mediwiki 做网站东莞网站建设做网站
  • 五台网站建设攀枝花网站seo
  • 小程序解析wordpressseo电商运营是什么意思
  • 大模型——上下文工程 (Context Engineering) – 现代 AI 系统的架构基础
  • 数据结构堆的实现(C语言)
  • Dify 1.6 安装与踩坑记录(Docker 方式)
  • 【算法300题】:双指针
  • 奥比中光双目摄像头实现物品抓取的机器人系统
  • 基于Arduino的智能寻迹小车设计