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 ...
随机推荐
- POSTMAN——环境变量
打开Manage Environment 设置几个自己的环境变量 可以在此看到设置的环境变量 在URL栏填写变量名,这个变量对应着百度的网址 send后可以查看回显 接下来设置全局变量,点开globa ...
- Selenium 启动无头浏览器,只有chrome 和 firefox的,没有IE
使用无头浏览器,可以避免掉不确定的弹出框对脚本稳定性的影响,还能在脚本执行过程中省略掉了css 加载的时间. 以下是Selenium 启动无头浏览器的方法,只有chrome 和 firefox的. p ...
- Flink State的两张图
streamTask的invoke方法中,会循环去调用task上的每个operator的initializeState方法,在这个方法中,会真正创建除了savepointStream的其他三个对象, ...
- 【bzoj1806】[Ioi2007]Miners 矿工配餐 dp
题目描述 有n个物品,每个都是3种之一.现要将这n个物品分成两个序列,对于每个序列中的每个物品,可以得到 它及它前面相邻的两个物品(不足则取全部)中不同种类的个数 的收益.问最大的总收益. 输入 输入 ...
- BZOJ5110 CodePlus2017Yazid 的新生舞会(线段树)
考虑统计每个数字的贡献.设f[i]为前缀i中该数的出现次数,则要统计f[r]-f[l]>(r-l)/2的数对个数,也即2f[r]-r>2f[l]-l. 注意到所有数的f的总变化次数是线性的 ...
- HDOJ.2064 汉诺塔III
汉诺塔III Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- 如何加快JavaScript的加载与执行
JS 有个很无语的阻塞特性,就是当浏览器在执行JS 代码时,不能同时做其他任何事情,无论其代码是内嵌的还是外部的. 浏览器在碰到一个引入外部JS 文件的<script>标签时会停下所有工作 ...
- handler更新ui线程的基本用法
1.因为费时操作要放子线程,更新UI要放UI线程(主线程),所以子线程和主线程通信,通信的话要用到handler这个东西. 这里讲的比较简单,举2个例子说明 2.使用post的是handler ,使用 ...
- 有关spring的各种下载资料的网站
spring的文件和jar包下载的网站: https://repo.spring.io/release/org/springframework/spring/ spring 各个版本源码下载的资料: ...
- 在Global.asax中过滤POST请求的非法参数。
using System;using System.Collections.Generic;using System.Collections.Specialized;using System.Linq ...