并查集解决。代码跑的有够慢。应该可以通过边权排序优化。

#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的更多相关文章

  1. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  2. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  3. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  4. 最长公共子序列(加强版) Hdu 1503 Advanced Fruits

    Advanced Fruits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  6. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  7. CodeForces 12C Fruits

    Fruits Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  8. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  9. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

随机推荐

  1. MySQL☞聚合函数/分组函数

    分组函数(聚合函数) 1.count(*/列名): a.*:求出该数据的总条数 select  count(*)  from 表名 b.列名:求出该列中列名不为null的总条数 select  cou ...

  2. Python全栈 MongoDB 数据库(数据的修改)

    修改操作符的使用   $set 修改一个域的值,增加一个域   阿哲年龄修改为33 db.class1.update({name:'阿哲'},{$set:{age:33}})   如果sex域不存在则 ...

  3. 论文翻译--StarCraft Micromanagement with Reinforcement Learning and Curriculum Transfer Learning

    (缺少一些公式的图或者效果图,评论区有惊喜) (个人学习这篇论文时进行的翻译[谷歌翻译,你懂的],如有侵权等,请告知) StarCraft Micromanagement with Reinforce ...

  4. Tensorflow编程基础之Mnist手写识别实验+关于cross_entropy的理解

    好久没有静下心来写点东西了,最近好像又回到了高中时候的状态,休息不好,无法全心学习,恶性循环,现在终于调整的好一点了,听着纯音乐突然非常伤感,那些曾经快乐的大学时光啊,突然又慢慢的一下子出现在了眼前, ...

  5. JavaSE复习(五)网络编程

    客户端:java.net.Socket 类表示.创建Socket对象,向服务端发出连接请求,服务端响应请求,两者建立连接开始通信 服务端:java.net.ServerSocket 类表示.创建Ser ...

  6. mac下使用clion构建boost库

    mac下使用clion构建boost库 使用brew install boost 完成后发现boost被安装在在/usr/local/Cellar/boost下 jetbrain给出的指导意见 htt ...

  7. 初学者学习python2还是python3?

    如果你是一个初学者,或者你以前接触过其他的编程语言,你可能不知道,在开始学习python的时候都会遇到一个比较让人很头疼的问题:版本问题!!是学习python2 还是学习 python3 ?这是非常让 ...

  8. 对TDD的实践感悟

    文章:我的TDD实践:可测试性驱动开发(上) 文章表达的思想是,达到一个目的并非只有一种套路,作者用写代码时,时刻考虑代码的可测试性,来推动项目的合理开发.

  9. HDU 2135 Rolling table

    http://acm.hdu.edu.cn/showproblem.php?pid=2135 Problem Description After the 32nd ACM/ICPC regional ...

  10. (转)mongdb性能优化收集

    一.数据库最大连接数问题当你在后台日志中,发现大量“connection refused because too many open connections: 819”信息时,一般跟你没有设置合适的最 ...