UVALIVE 3939 Plucking fruits
并查集解决。代码跑的有够慢。应该可以通过边权排序优化。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
#define MAXN 1010
int p[MAXN];
int Find(int x) {return x == p[x] ? x : p[x] = Find(p[x]);}
int N,M,R;
struct node
{
int u,v,w;
friend bool operator < (const node &a,const node &b)
{
return a.w < b.w;
}
}src[MAXN * MAXN];
bool judge(int s,int t)
{
int x =Find(s);
int y = Find(t);
if (x == y) return true;
return false;
}
bool query(int s,int t,int least)
{
for (int i = ; i < M ; i++)
{
if (src[i].w < least) continue;
int x = Find(src[i].u), y = Find(src[i].v);
if (x != y) p[x] = y;
if (judge(s,t))
{
return true;
}
}
return false;
}
int main()
{
int kase = ;
while (cin >> N >> M >> R)
{
cout << "Case " << kase++ << ':' << endl;
for (int i = ; i < M ;i++)
cin >> src[i].u >> src[i].v >> src[i].w;
for (int i = ; i < R; i++)
{
int u ,v,w;
for (int i = ;i <= N ; i++) p[i] = i;
cin >> u >> v >> w;
if (query(u,v,w)) puts("yes");
else puts("no");
}
}
return ;
}
UVALIVE 3939 Plucking fruits的更多相关文章
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 最长公共子序列(加强版) Hdu 1503 Advanced Fruits
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- CodeForces 12C Fruits
Fruits Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
随机推荐
- JAVA集合面面观
List的常用实现:vector,ArrayList,linkedList. 总体关系如下(java8): vector和arraylist 两者底层都是采用数组的形式.但是有些许不同 // Arra ...
- 1.爬虫 urlib库讲解 Handler高级用法
在前面我们总结了urllib库的 urlopen()和Request()方法的使用,在这一小节我们要使用相关的Handler来实现代理.cookies等功能. 写在前面: urlopen()方法不支持 ...
- 预处理器&预处理变量&头文件保护&条件编译
[常见的预处理功能] #include 头文件保护符 条件编译 [预处理器] 编译之前执行的一段程序,可以部分地改变我们所写的程序 举个例子:当预处理器看到#include标记时就会用指定的头文件的内 ...
- DP入门(2)——DAG上的动态规划
有向无环图(DAG,Directed Acyclic Graph)上的动态规划是学习动态规划的基础.很多问题都可以转化为DAG上的最长路.最短路或路径计数问题. 一.DAG模型 [嵌套矩形问题] 问题 ...
- 关闭电脑自带键盘(copy)
用管理员身份运行cmd: 禁用笔记本键盘 sc config i8042prt start= disabled 启用笔记本键盘 sc config i8042prt start= auto
- 浅谈c语言和c++中struct的区别
今天做二叉树的时候,发现利用结构体有点乱,不知道怎么回事,我之前知道c语言中声明一个结构体变量时需要通过 struct 结构体名 变量名,而在c++中,可以不要struct,由于可以利用typedef ...
- springMVC前后台数据交互
假设项目需求是在springMVC框架下,后台要传送一个list到前台,那我们就要做以下几个步骤: 1 在web.xml文件中进行springMVC的配置: <?xml version=&quo ...
- not1,not2,bind1st,bind2nd
例子需要包含头文件 #include <vector> #include <algorithm> #include <functional> bind1st和bin ...
- 【Python】- 如何使用Visual Studio 2013编写python?
安装Visual Studio 2013 1.VS2013下载安装略 安装python2.7 1.从官网下载python2.7,下载地址:https://www.python.org/getit/ ...
- JS设置cookie,读取cookie,删除cookie
总结了一下cookie的使用,不全面.都是基础的知识,后期还会再添加. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...