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

#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 ;
}

最新文章

  1. Atitit HTTP 认证机制基本验证 (Basic Authentication) 和摘要验证 (Digest Authentication)attilax总结
  2. DB2 runstats、reorgchk、reorg 命令
  3. 彻底解决Eclipse自动补全变量名及变量名后面追加类型名
  4. 揭秘Sql2014新特性-tempdb性能提升
  5. Leetcode 299 Bulls and Cows 字符串处理 统计
  6. pageX和pageY
  7. django-cms 代码研究(七)杂七杂八
  8. &lt; java.lang &gt;-- String字符串
  9. java中的容器问题
  10. Java接口修饰符详解
  11. android抓日志
  12. Jenkins构建本地项目到服务器上自动部署的方法
  13. 值得注意的CSS属性
  14. ASP.NET Core WebApi中使用FluentValidation验证数据模型
  15. Ansible工具原理一
  16. 百度地图bd map使用方法
  17. 复刻smartbits的国产网络测试工具minismb-如何测试DPI引擎
  18. hdu 1166 线段树(单点增减 区间求和)
  19. Android 查看和管理sqlite数据库
  20. 使用weinre调试Web应用及PhoneGap应用

热门文章

  1. Ruby中数组的&amp;操作
  2. Leetcode 679.24点游戏
  3. Cassandra 在CQL中使用函数
  4. 前端开发神器Sublime Text2/3之安装使用(windows7/Mac)
  5. Java 8手动实现一个Collector
  6. Mac上利用Aria2加速百度网盘下载
  7. Vue组件间通信:一个例子学会Vue组件-Vue.js学习总结)(转载)
  8. P1196 [NOI2002]银河英雄传说
  9. 我的emacs配置部分
  10. [CF895C]Square Subsets