题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1050 思路: 先将每条边的权值排个序优先小的,然后从小到大枚举每一条边,将其存到并查集里,如果得到的比值比之前的小,那么判断下s与t能否连通,如果连通就替换就好了 实现代码: #include<bits/stdc++.h> using namespace std; ; int f[M],vis[M],a[M]; int n,m; int Find(int x){ if(x==f[x…
A. Arpa’s hard exam and Mehrdad’s naive cheat time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Me…
<传送门> 128. Snake time limit per test: 0.25 sec. memory limit per test: 4096 KB There are N points given by their coordinates on a plane. All coordinates (xi,yi) are integers in a range from -10000 up to 10000 inclusive . It is necessary to construct…
传送门 边数只有5000,可以考虑\(O(m^2)\)算法,即把所有边按边权升序排序,然后依次枚举每条边\(i\),从这条边开始依次加边,加到起点和终点在一个连通块为止.这个过程可以用并查集维护.那么以\(i\)这条边为最小边的合法路径,最大值最小的边就是最后加进去的边,这时用这两个边权更新答案即可 可以加一些形如当前比值比答案更差就退出的剪枝 #include<bits/stdc++.h> #define LL long long #define il inline #define re r…
思路:枚举边集,最小生成树 提交:1次 题解:枚举最长边,添加较小边. #include<cstdio> #include<iostream> #include<algorithm> #define R register int using namespace std; #define ull unsigned long long #define ll long long #define pause (for(R i=1;i<=10000000000;++i))…
题目描述 动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形.A 吃 B,B 吃 C,C 吃 A. 现有 N 个动物,以 1 - N 编号.每个动物都是 A,B,C 中的一种,但是我们并不知道 它到底是哪一种. 有人用两种说法对这 N 个动物所构成的食物链关系进行描述: 第一种说法是“1 X Y”,表示 X 和 Y 是同类. 第二种说法是“2 X Y”,表示 X 吃 Y . 此人对 N 个动物,用上述两种说法,一句接一句地说出 K 句话,这 K 句话有的是真 的,有的是假的.当…
Description Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M,T,分别表示节点数.初始边数.操作数.第三行包含N个非负整数表示 N个节点上的权值. 接下来 M行,每行包含两个整数x和 y,表示初始的时候,点x和点y 之间有一条无向边, 接下来 T行,每行描述一个操作,格式为“Q x y k”或者“L x y ”,其含义见题目描述部分. Output 对于每一个第一类操作,输出一个非负整数表示答…
A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Bein…
D. Dividing Kingdom II 题目连接: http://www.codeforces.com/contest/687/problem/D Description Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so…