Peaks

这是一个关于图论的算法问题,给定n个观测站和m条道路,每个观测站有其海拔高度。目标是找出那些比直接相连的观测站海拔高的或者无法通过一条道路到达其他观测站的观测站数量。输入包括观测站数量、道路数量及各站海拔,输出是符合条件的观测站数目。题目中提到可能存在多条连接相同观测站的道路,并且允许存在没有道路连接的观测站。
摘要由CSDN通过智能技术生成

Peaks

题目描述

There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, …, Obs. N. The elevation of Obs. i is Hi. There are also M roads, each connecting two different observatories. Road j connects Obs. Aj and Obs. Bj.Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road. Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.

Constraints·2≤N≤105·1≤M≤105·1≤Hi≤109·1≤Ai,Bi≤N·Ai≠Bi·Multiple roads may connect the same pair of observatories.·All values in input are integers.

输入

Input is given from Standard Input in the following format:

N M
H1 H2 … HN
A1 B1
A2 B2
:
AM BM

输出

Print the number of good observatories.

样例输入 [Copy](javascript:CopyToClipboard($(’#sampleinput’).text()))
【样例1】
4 3
1 2 3 4
1 3
2 3
2 4
【样例2】
6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6
样例输出 [Copy](javascript:CopyToClipboard($(’#sampleoutput’).text()))
【样例1】
2
【样例2】
3
提示

样例1解释:
·From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.
·From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.
·From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.
·From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.
Thus, the good observatories are Obs. 3 and 4, so there are two good observatories.

题意:

n个点,m条连线,求有几个顶点是连着比自己小的数与没有连线的点的个数和

思路:

设置一个结构体,f来判断该顶点有没有连线,t来判断有没有连入比自己大的顶点z,最后判断一下求和

代码:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int N=100010;
int n,m,ans;
int a[N];
struct node{
	int t=0,f=0;
}q[N];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		q[x].f=1,q[y].f=1;
		if(a[x]<=a[y]) q[x].t=1;
		if(a[y]<=a[x]) q[y].t=1;
	} 
	/*for(int i=1;i<=n;i++){
		cout<<q[i].f<<"  "<<q[i].t<<endl;
	}*/
	for(int i=1;i<=n;i++){
		if(q[i].f==0) ans++;
		else if(q[i].t==0) ans++;
	}
	cout<<ans;
	return 0;
} 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值