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 ...
随机推荐
- browsersync的安装与基本使用
browser-sync启动命令 Browsersync能让浏览器实时.快速响应您的文件更改(html.js.css.sass.less等)并自动刷新页面. 官网文档:http://www.brows ...
- Leetcode 672.灯泡开关II
灯泡开关II 现有一个房间,墙上挂有 n 只已经打开的灯泡和 4 个按钮.在进行了 m 次未知操作后,你需要返回这 n 只灯泡可能有多少种不同的状态. 假设这 n 只灯泡被编号为 [1, 2, 3 . ...
- python中通过string类名获得实例
原文:https://bytes.com/topic/python/answers/42866-how-create-object-instance-string Ksenia Marasanova的 ...
- Spring Data学习(一):初识
目录 前言 添加Spring Data 配置pom.xml 配置数据库相关信息(application.properties) 配置数据库信息 配置自动根据实体类在数据库创建表 创建User.java ...
- Mac OSX 10.11安装Jekyll
一说常见的博客管理工具大家想到的就是WordPress.不过现在部分个人博客用户开始从WordPress转移到Jekyll上了.Jekyll是一种本地生成静态页面进而线上发布的博客工具,而且现在已经有 ...
- Hadoop Yarn on Docker
搭建Hadoop Yarn on Docker 一.概览 Docker基于Linux Container技术整合了一堆易用的接口用于构建非常轻量级的虚拟机.Docker Container Execu ...
- 【bzoj2124】等差子序列 STL-bitset
题目描述 给一个1到N的排列{Ai},询问是否存在1<=p1<p2<p3<p4<p5<…<pLen<=N (Len>=3),使得Ap1,Ap2,A ...
- Numpy array学习笔记
- [洛谷P2584][ZJOI2006]GameZ游戏排名系统
题目大意:同[洛谷P4291][HAOI2008]排名系统(双倍经验) 题解:略 卡点:无 C++ Code: #include <cstdio> #include <map> ...
- [洛谷P3376]【模板】网络最大流(ISAP)
C++ Code:(ISAP) #include <cstdio> #include <cstring> #define maxn 1210 #define maxm 1200 ...