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

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <deque>
  7. #include <stack>
  8. #include <queue>
  9. #include <cctype>
  10. #include <cstdio>
  11. #include <string>
  12. #include <vector>
  13. #include <climits>
  14. #include <cstdlib>
  15. #include <cstring>
  16. #include <iostream>
  17. #include <algorithm>
  18. #define LL long long
  19. #define PI 3.1415926535897932626
  20. using namespace std;
  21. int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
  22. #define MAXN 1010
  23. int p[MAXN];
  24. int Find(int x) {return x == p[x] ? x : p[x] = Find(p[x]);}
  25. int N,M,R;
  26. struct node
  27. {
  28. int u,v,w;
  29. friend bool operator < (const node &a,const node &b)
  30. {
  31. return a.w < b.w;
  32. }
  33. }src[MAXN * MAXN];
  34. bool judge(int s,int t)
  35. {
  36. int x =Find(s);
  37. int y = Find(t);
  38. if (x == y) return true;
  39. return false;
  40. }
  41. bool query(int s,int t,int least)
  42. {
  43. for (int i = ; i < M ; i++)
  44. {
  45. if (src[i].w < least) continue;
  46. int x = Find(src[i].u), y = Find(src[i].v);
  47. if (x != y) p[x] = y;
  48. if (judge(s,t))
  49. {
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. int main()
  56. {
  57. int kase = ;
  58. while (cin >> N >> M >> R)
  59. {
  60. cout << "Case " << kase++ << ':' << endl;
  61. for (int i = ; i < M ;i++)
  62. cin >> src[i].u >> src[i].v >> src[i].w;
  63. for (int i = ; i < R; i++)
  64. {
  65. int u ,v,w;
  66. for (int i = ;i <= N ; i++) p[i] = i;
  67. cin >> u >> v >> w;
  68. if (query(u,v,w)) puts("yes");
  69. else puts("no");
  70. }
  71. }
  72. return ;
  73. }

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. browsersync的安装与基本使用

    browser-sync启动命令 Browsersync能让浏览器实时.快速响应您的文件更改(html.js.css.sass.less等)并自动刷新页面. 官网文档:http://www.brows ...

  2. Leetcode 672.灯泡开关II

    灯泡开关II 现有一个房间,墙上挂有 n 只已经打开的灯泡和 4 个按钮.在进行了 m 次未知操作后,你需要返回这 n 只灯泡可能有多少种不同的状态. 假设这 n 只灯泡被编号为 [1, 2, 3 . ...

  3. python中通过string类名获得实例

    原文:https://bytes.com/topic/python/answers/42866-how-create-object-instance-string Ksenia Marasanova的 ...

  4. Spring Data学习(一):初识

    目录 前言 添加Spring Data 配置pom.xml 配置数据库相关信息(application.properties) 配置数据库信息 配置自动根据实体类在数据库创建表 创建User.java ...

  5. Mac OSX 10.11安装Jekyll

    一说常见的博客管理工具大家想到的就是WordPress.不过现在部分个人博客用户开始从WordPress转移到Jekyll上了.Jekyll是一种本地生成静态页面进而线上发布的博客工具,而且现在已经有 ...

  6. Hadoop Yarn on Docker

    搭建Hadoop Yarn on Docker 一.概览 Docker基于Linux Container技术整合了一堆易用的接口用于构建非常轻量级的虚拟机.Docker Container Execu ...

  7. 【bzoj2124】等差子序列 STL-bitset

    题目描述 给一个1到N的排列{Ai},询问是否存在1<=p1<p2<p3<p4<p5<…<pLen<=N (Len>=3),使得Ap1,Ap2,A ...

  8. Numpy array学习笔记

  9. [洛谷P2584][ZJOI2006]GameZ游戏排名系统

    题目大意:同[洛谷P4291][HAOI2008]排名系统(双倍经验) 题解:略 卡点:无 C++ Code: #include <cstdio> #include <map> ...

  10. [洛谷P3376]【模板】网络最大流(ISAP)

    C++ Code:(ISAP) #include <cstdio> #include <cstring> #define maxn 1210 #define maxm 1200 ...