Road

Road
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB
Total submit users: 23, Accepted users: 20
Problem 12934 : No special judgement
Problem description

In one country, there are N cities, numbered 1 to N. A civil engineer has to build public roads that connect all the cities together, i.e., it must be possible to travel from all cities to any other cities, maybe going through multiple cities. His team has surveyed several routes (candidate road between any two cities). Each route is a bi- directional connection between two cities. He can build a bi-directional road on the surveyed route for a specific cost (The shorter the route is the cheaper the road).

This engineer has never planned a road system in advance. He would just pick one of the routes based on his preference, and build a road until all the cities are connected.

Right now this engineer is going to build a road from the city p to the city q. With pressure from the government to reduce the cost, he asks you to write a program to decide, if he should build this road or not. Your program should say yes if the building of this road guaranteed that it can be part of the shortest road system that connects all cities together. Otherwise, your program should say no.


Input

First line of input is a number of test cases T ≤ 10.

Each test case start with a line contains 4 integers N, M, p, and q.

N (2 ≤ N ≤ 10 000) is the number of cities in this road system.

M (1 ≤ M ≤ 20 000) is the number of surveyed routes.

p and q (1 ≤ p ≤ N and 1 ≤ q ≤ N) indicate the route between two cities,

that the engineer asks if he can build a road or not. Then, the each of the following M lines contains 3 numbers u, v, and w (1 ≤ u ≤ N, 1 ≤ v ≤ N, 1 ≤ w ≤ 400 000) indicates that there are the bidirectional route of length w between u and v. The length of each road in the current system is unique. And, there is only one possible road between two cities. The input guarantees that at least one road system has a route between any two cities. All numbers are integer.


Output

For each test case, display YES if the engineer can build a road p-q as part of the shortest road system. Otherwise, print NO.


Sample Input
3
2 1 1 2
1 2 4
3 3 2 3
1 2 1
1 3 2
2 3 3
4 5 3 4
1 2 1
1 3 3
3 4 2
1 4 4
4 2 5
Sample Output
YES
NO
YES
#include<iostream>//不想说了,我再也不用模版了,自己做自己想 
#include<cstring>//加入变后合并这两个点 
#include<cstdlib>//8.24.ROAD 
#include<algorithm>
#include<cstdio>
#define MAXM 40010
#define MAXN 20010
using namespace std;
bool flag;
int n,m,strx,stry,strnum,k,ans;
struct EDGE
{
	int u,v,w;
}edge[MAXM];

bool cmp(EDGE a,EDGE b)
{
	return a.w<b.w;
}

void read(int *x)
{
    char ch;
    (*x) = 0;
    while((ch = getchar()) > 47 && ch < 58)
    {
        (*x) *= 10;
        (*x) += ch - '0';
    }
}



void union_point(int a,int b)//??
{
	for(int i=0;i<m;i++)
	{
		if(edge[i].u==b)
		edge[i].u=a;
		if(edge[i].v==b)
		edge[i].v=a;
	}
}
void kruskal()
{
	sort(edge+1,edge+1+m,cmp);
	for(int i=1;i<=m;i++)
	{
		if(edge[i].u!=edge[i].v)
		{
			//cout<<edge[i].u<<" "<<edge[i].v<<endl;
			if(i==strnum)
			{
				flag=1;
				return;
			}
			ans+=edge[i].w;
			k++;
			union_point(edge[i].u,edge[i].v);
		}
		if(k==n-1)
	    return;
	}
}

int main()
{
    int cas;
	cin>>cas;
	while(cas--)
	{
		flag=0;
		k=0;ans=0;
		cin>>n>>m>>strx>>stry; 
		for(int i=1;i<=m;i++)
		{
			int x,y,value;
			cin>>x>>y>>value;
			edge[i].u=x;
			edge[i].v=y;
			edge[i].w=value;
		}
		strnum=-1;
		for(int i=1;i<=m;i++)
		{
			if(edge[i].u==strx&&edge[i].v==stry)
			{
			
			strnum=i;
			break;
		    }
			if(edge[i].u==stry&&edge[i].v==strx)
			{
			
			strnum=i;
		    break;
		    }
		}
		kruskal();
		if(flag)
		printf("YES\n");
		else
		printf("NO\n");
	}
	return 0;	
}


基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据库进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机会。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值