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