CodeForces 14D 树的直径 Two Paths】的更多相关文章

给出一棵树,找出两条不相交即没有公共点的路径,使得两个路径的长度的乘积最大. 思路:枚举树中的边,将该边去掉,分成两棵树,分别求出这两棵树的直径,乘起来维护一个最大值即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; int n; struct Edge { int u, v, nxt; bool…
题目链接 set维护最小值贪心, 刚开始用树的直径+单调队列没调出来... #include <iostream>#include <cstdio> #include <set> #define REP(i,a,n) for(int i=a;i<=n;++i) #define x first #define y second using namespace std; typedef pair<int,int> pii; , INF = 0x3f3f3f…
题意:每次操作新加两个叶子节点,每次操作完以后询问树的直径. 维护树的直径的两个端点U,V,每次计算一下新加进来的叶子节点到U,V两点的距离,如果有更长的就更新. 因为根据树的直径的求法,若出现新的直径,一定是到U或者到V距离最远. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> + ; ; int n, Q; int L[maxn]; int fa[…
题意:有两个小孩玩游戏,每个小孩可以选择一个起始点,并且下一个选择的点必须和自己选择的上一个点相邻,问两个选的点权和的最大值是多少? 思路:首先这个问题可以转化为求树上两不相交路径的点权和的最大值,对于这种问题,我们有两种想法: 1:树的直径,受之前HDU多校的那道题的启发,我们先找出树的直径,然后枚举保留直径的哪些部分,去找保留这一部分的最优解,去更新答案. 代码: #include <bits/stdc++.h> #define INF 1e18 #define LL long long…
题目链接:点击打开链接 题意:给定一棵树 找2条点不反复的路径,使得两路径的长度乘积最大 思路: 1.为了保证点不反复,在图中删去一条边,枚举这条删边 2.这样得到了2个树,在各自的树中找最长链.即树的直径,然后相乘就可以 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #inclu…
题目链接: http://codeforces.com/contest/14/problem/D D. Two Paths time limit per test2 secondsmemory limit per test64 megabytes 问题描述 As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The citie…
D. Two Paths time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are n…
tiyi:给你n个节点和n-1条边(无环),求在这个图中找到 两条路径,两路径不相交,求能找的两条路径的长度的乘积最大值: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <stack>…
 Two Paths Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered…
题目链接: http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” consists of n servers and m two-way communication links. Two servers can communicate either through a direct link, or through a chain of links, by relayi…