Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 1728   Accepted: 643
Case Time Limit: 2000MS

Description

“Highways are built, then life is rich.” Now people of Big Town want to become rich, so they are planning to build highways to connect their villages.

Big Town is really big and has many villages. Its people plan to build some highways between some pairs of villages so that every pair of villages is connected by the highways either directly or indirectly. After surveying the geographical surroundings, they find that there are some paths along with highways can be built. Every path is denoted by a triplet (abc) which means a highway can built between the a-th village and the b-th village with a cost of c. In order to save money, they will select only part of the paths to build highways along so that the total cost to build highways along the selected paths is minimal under the condition that every pair of villages is connected.

It is possible that multiple such selections exist. People from every village want to have those highways of good interest to them built. But some highways can never appear in the selection since they are much too costly. So people ask whether a certain highway can be selected if they agree to cut the cost. Your task is to design a program to answer their queries.

Input

The first line of input contains three integers NM and Q (1 < N ≤ 1,000, N − 1 ≤ M ≤ 100,000, 0 < Q ≤ 100,000), where N is the number of villages, M is the number of paths, and Q is the number of queries. Each of the next M lines contains three integers ab, and c (1 ≤ ab ≤ Na ≠ b, 0 ≤ c ≤ 1,000,000). The triplet (abc) describes a path. Each of following Q lines contains two integer i and x (1 ≤ i ≤ M, 0 ≤ x) describing a query, “Can a highway be built along the i-th path if the cost of is reduced to x?” x is strictly lower than the original cost of building a highway along the i-th path. It is assumed that every pair of village will be connected either directly or indirectly if all possible highways are built. And there may be more than one highway that can be built between a pair of villages.

Output

Output one line for each query. Output either “Yes” or “No” as the answer to the the query.

Sample Input

3 4 3
1 2 10
1 3 6
2 3 4
1 3 7
4 6
1 7
1 5

Sample Output

Yes
No
Yes

Source

 
次小生成树+不知道是不是的spfa
如果降低后费用小于等于两点间的最大费用,则输出Yes.
否则输出No.
prim算法好写些,但我忘记怎么写了。。
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#define M 100005
#define N 1005 using namespace std;
struct Edge
{
int x,y,z;
bool operator <(Edge a)const
{
return z<a.z;
}
}edge[M],oedge[M];
bool vis[N];
int fa[N],n,m,q,dist[N][N];
int find_(int x) {return x==fa[x]?x:fa[x]=find_(fa[x]);}
struct node
{
int to,dis;
node (int to=,int dis=) : to(to),dis(dis) {}
};
vector<node>vec[N];
void update(int s)
{
memset(vis,,sizeof(vis));
dist[s][s]=;
vis[s]=;
queue<int>Q;
Q.push(s);
for(int now=Q.front();!Q.empty();Q.pop(),now=Q.front())
{
for(int i=;i<vec[now].size();i++)
{
int v=vec[now][i].to,w=vec[now][i].dis;
if(vis[v]) continue;
dist[s][v]=max(dist[s][now],w);
vis[v]=;
Q.push(v);
}
}
}
int main()
{
scanf("%d%d%d",&n,&m,&q);
for(int a,b,c,i=;i<=m;i++)
{
scanf("%d%d%d",&a,&b,&c);
edge[i].x=a;
edge[i].y=b;
edge[i].z=c;
oedge[i]=edge[i];
}
for(int i=;i<=n;i++) fa[i]=i;
sort(edge+,edge++m);
int num=;
for(int i=;i<=m;i++)
{
int fx=find_(edge[i].x),fy=find_(edge[i].y);
if(fx!=fy)
{
fa[fy]=fx;
num++;
vec[edge[i].x].push_back(node(edge[i].y,edge[i].z));
vec[edge[i].y].push_back(node(edge[i].x,edge[i].z));
if(num==n-) break;
}
}
for(int i=;i<=n;i++) update(i);
for(int xx,yy;q--;)
{
scanf("%d%d",&xx,&yy);
if(dist[oedge[xx].x][oedge[xx].y]>=yy) printf("Yes\n");
else printf("No\n");
}
return ;
}

最新文章

  1. ORACLE操作列
  2. 如何清除SQL Server Management Studio的最近服务器列表
  3. 《CLR.via.C#第三版》第一部分读书笔记(一)
  4. Servlet3.0学习总结——基于Servlet3.0的文件上传
  5. css ul li 水平布局问题
  6. php添加环境变量
  7. PCL—低层次视觉—点云滤波(初步处理)
  8. uva 1298 - Triathlon
  9. IRP派遣操作
  10. 《Effective C++》:条款46-条款47
  11. 【Linux相识相知】yum的配置使用和程序包的编译安装
  12. win10 如何让其他机器访问自己机器上的mysql
  13. PostgreSQL的insert注入
  14. 环境准备阶段--搭建oracle linux 6.5系统
  15. ContentProvider插件化解决方案
  16. CEF 设置Cookie
  17. Spark:几种给Dataset增加列的方式、Dataset删除列、Dataset替换null列
  18. 比较实用的前端 js框架 ,组件 汇总
  19. OS之进程管理---孤儿进程和僵尸进程
  20. WebRTC详解-zz

热门文章

  1. python_xrange和range的异同
  2. Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力
  3. Flutter实战视频-移动电商-33.列表页_子类和商品列表交互效果
  4. 【转】NET中管理数字证书(Digital Certificate)的一些类
  5. -webkit-line-clamp 兼容性问题
  6. LVS 负载均衡器总结
  7. VC++6.0下新建工程中有17个选项,都是做什么用的?
  8. SpringBoot | Thymeleaf | 局部更新
  9. scrapy框架中Spiders用法
  10. SVG图像学习