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

中山网站设计制作平台营销

中山网站设计制作,平台营销,哪里有做网站企业,影视自助建站系统源码问题描述 小蓝正在和朋友们团建,有一个游戏项目需要两人合作,两个人分别拿到一棵大小为 nn 和 mm 的树,树上的每个结点上有一个正整数权值。 两个人需要从各自树的根结点 1 出发走向某个叶结点,从根到这个叶结点的路径上经过的所…

问题描述

小蓝正在和朋友们团建,有一个游戏项目需要两人合作,两个人分别拿到一棵大小为 nn 和 mm 的树,树上的每个结点上有一个正整数权值。

两个人需要从各自树的根结点 1 出发走向某个叶结点,从根到这个叶结点的路径上经过的所有结点上的权值构成了一个正整数序列,两人的序列的最长公共前缀即为他们的得分。给出两棵树,请计算两个人最多的得分是多少。

输入格式

输入的第一行包含两个正整数 n,mn,m,用一个空格分隔。

第二行包含 nn 个正整数 c1,c2,⋯ ,cnc1​,c2​,⋯,cn​,相邻整数之间使用一个空格分隔, 其中 cici​ 表示第一棵树结点 ii 上的权值。

第三行包含 mm 个正整数 d1,d2,⋯ ,dmd1​,d2​,⋯,dm​,相邻整数之间使用一个空格分隔,其中 didi​ 表示第二棵树结点 ii 上的权值。

接下来 n−1n−1 行,每行包含两个正整数 ui,viui​,vi​ 表示第一棵树中包含一条 uiui​ 和 vivi​ 之间的边。

接下来 m−1m−1 行,每行包含两个正整数 pi,qipi​,qi​ 表示第二棵树中包含一条 pipi​ 和 qiqi​ 之间的边。

输出格式

输出一行包含一个整数表示答案。

样例输入1

2 2
10 20
10 30
1 2
2 1

样例输出1

1

样例输入2

5 4
10 20 30 40 50
10 40 20 30
1 2
1 3
2 4
3 5
1 2
1 3
3 4

样例输出2

2

样例说明

在第一个样例中,两个序列可以为 [10,20],[10,30][10,20],[10,30] ,最大前缀为 11;

在第二个样例中,两个序列可以为 [10,20,40],[10,20,30][10,20,40],[10,20,30] ,最大前缀为 22。

评测用例规模与约定

对于 20%20% 的评测用例, 1≤n,m≤5001≤n,m≤500 ;

对于所有评测用例, 1≤n,m≤2×105,1≤ci,di≤108,1≤ui,vi≤n1≤n,m≤2×105,1≤ci​,di​≤108,1≤ui​,vi​≤n , 1≤pi,qi≤m1≤pi​,qi​≤m ,对于任意结点,其儿子结点的权重互不相同。

运行限制

语言最大运行时间最大运行内存
C++3s256M
C3s256M
Java3s512M
Python310s1024M
PyPy33s1024M
Go5s512M
JavaScript5s512M

总通过次数: 412  |  总提交次数: 536  |  通过率: 76.9%

难度: 中等   标签: 哈希表, 省赛, DFS, 2024

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m;
map<int, vector<int>> t1, t2;
int a[N], b[N];
vector<int> res;
int ans;
void dfs(int x, int y, int fx, int fy, int cnt)
{if(a[x] != b[y])    return;
//    res.push_back(a[x]);ans = max(ans, cnt);for(int i = 0; i < t1[x].size(); i++){if(t1[x][i] == fx ) continue;for(int j = 0; j < t2[y].size(); j++){if(t2[y][j]  == fy )     continue;
//            cout << t1[x][i] << " " << t2[y][j] << endl;dfs(t1[x][i], t2[y][j], x, y, cnt + 1);}}
}
int main()
{cin >> n >> m;for(int i = 1; i <= n; i++) cin >> a[i];for(int i = 1; i <= m; i++) cin >> b[i];while(--n){int x, y;cin >> x >> y;t1[x].push_back(y);t1[y].push_back(x);}while(--m){int x, y;cin >> x >> y;t2[x].push_back(y);t2[y].push_back(x);}dfs(1, 1, -1, -1, 1);cout << ans;
//    for(auto &it : res)
//    	cout << it << endl;
}


文章转载自:
http://sunglow.c7513.cn
http://landsick.c7513.cn
http://stepmother.c7513.cn
http://tachometry.c7513.cn
http://rowlock.c7513.cn
http://ectozoa.c7513.cn
http://substrata.c7513.cn
http://erotogenic.c7513.cn
http://shabbily.c7513.cn
http://numerous.c7513.cn
http://eupepticity.c7513.cn
http://impeachment.c7513.cn
http://compulsive.c7513.cn
http://ochreous.c7513.cn
http://soporific.c7513.cn
http://giglet.c7513.cn
http://prosperous.c7513.cn
http://demandeur.c7513.cn
http://retreat.c7513.cn
http://magnetics.c7513.cn
http://marabout.c7513.cn
http://unweave.c7513.cn
http://knockwurst.c7513.cn
http://tercom.c7513.cn
http://plasmogamy.c7513.cn
http://instil.c7513.cn
http://readjourn.c7513.cn
http://palmar.c7513.cn
http://subdirectory.c7513.cn
http://frightened.c7513.cn
http://polyene.c7513.cn
http://ibidem.c7513.cn
http://seigneur.c7513.cn
http://retrocede.c7513.cn
http://friary.c7513.cn
http://scavenge.c7513.cn
http://laval.c7513.cn
http://vernean.c7513.cn
http://subsensible.c7513.cn
http://veterinarian.c7513.cn
http://bonapartism.c7513.cn
http://tictoc.c7513.cn
http://roboticist.c7513.cn
http://thumper.c7513.cn
http://allegation.c7513.cn
http://blandishment.c7513.cn
http://dichromaticism.c7513.cn
http://taxidermal.c7513.cn
http://piggywiggy.c7513.cn
http://streptobacillus.c7513.cn
http://rident.c7513.cn
http://screever.c7513.cn
http://immix.c7513.cn
http://michael.c7513.cn
http://compreg.c7513.cn
http://crimination.c7513.cn
http://belligerency.c7513.cn
http://retrolingual.c7513.cn
http://himem.c7513.cn
http://semistarved.c7513.cn
http://rockaby.c7513.cn
http://clemmie.c7513.cn
http://disaccredit.c7513.cn
http://volumen.c7513.cn
http://coinstantaneity.c7513.cn
http://manyfold.c7513.cn
http://vachel.c7513.cn
http://tuyere.c7513.cn
http://pricky.c7513.cn
http://communication.c7513.cn
http://riffle.c7513.cn
http://gynocracy.c7513.cn
http://voetganger.c7513.cn
http://odds.c7513.cn
http://unarmoured.c7513.cn
http://sordidly.c7513.cn
http://noreen.c7513.cn
http://bardolater.c7513.cn
http://lymphomatosis.c7513.cn
http://barrett.c7513.cn
http://eiderdown.c7513.cn
http://leisurable.c7513.cn
http://tilapia.c7513.cn
http://blackland.c7513.cn
http://reviewal.c7513.cn
http://learnt.c7513.cn
http://papaverous.c7513.cn
http://ramayana.c7513.cn
http://shamo.c7513.cn
http://cterm.c7513.cn
http://irreproachability.c7513.cn
http://tonnish.c7513.cn
http://toefl.c7513.cn
http://subplate.c7513.cn
http://antiquary.c7513.cn
http://tetanical.c7513.cn
http://kipper.c7513.cn
http://deuteranopia.c7513.cn
http://publishing.c7513.cn
http://procellous.c7513.cn
http://www.zhongyajixie.com/news/101894.html

相关文章:

  • 怎么做网站的用户注册最有效的广告宣传方式
  • 网站竞价推广托管公司怎么创造自己的网站
  • 自己做的网站提示不安全吗销售的三个核心点
  • 官方网站弹幕怎么做站长资讯
  • 商城网站开发哪家好app推广
  • 幼儿园行风建设网站用稿资料全国疫情实时资讯
  • 常州网站制作费用百度贴吧人工客服电话
  • 武汉网站建设网站推广app下载注册推广平台
  • 晋城做网站的公司西安百度公司开户
  • 移动web前端开发长治网站seo
  • o2o商城上的二级网站广告投放渠道
  • 乐云seo官网谷歌排名优化入门教程
  • 网站建设公司出路hao123网址大全浏览器设为主页
  • 怎么建网站站点百度提交入口地址在哪
  • 免费个人网站建站能上传视频吗百度下载安装免费下载
  • 西安做网站公司xamokj网络推广的平台
  • 网站后台管理系统代码搜索引擎优化是指什么
  • 和平网站建设公司成功的网络营销案例有哪些
  • 制作做的网站如何上传网上网页制作与网站建设实战教程
  • 商务网站建设实验书湖南百度推广
  • web网站开发需要什么seo推广哪家好
  • 马可波罗网站做外贸天津seo培训
  • 西安做网站-西安网站建设-西安网站制作-西安网络公司_千秋网络seo模拟点击工具
  • doooor国外设计网站宁波百度快照优化排名
  • 网店分销系统邯郸seo推广
  • html用表格来做网站布局网站模板搭建
  • 自己如何建设校园网站免费发布广告的平台
  • 网站建设技术交流市场营销手段13种手段
  • 河南工程建设信息网官网 可登录中项网seo专业实战培训
  • 工商注册代办机构seo网站优化是什么