접근 방법
- 그래프..? 인가?
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> weight;
vector<vector<int>> friendship;
bool check(int p){
vector<int> temp;
for(auto i: friendship[p]){
temp.push_back(weight[i]);
}
if(temp.empty()){return true;}
if(weight[p] > *max_element(temp.begin(), temp.end())){return true;}
else{return false;}
}
int main(int argc, char** argv)
{
int n, m, answer = 0;
scanf("%d %d", &n, &m);
weight = {0};
friendship = vector<vector<int>>(n+1);
for(int i = 0; i < n; ++i){
int w;
scanf("%d", &w);
weight.push_back(w);
}
for(int i = 0; i < m; ++i){
int a, b;
scanf("%d %d", &a, &b);
friendship[a].push_back(b);
friendship[b].push_back(a);
}
for(int i = 1; i <= n; ++i){
if(check(i)){++answer;}
}
printf("%d", answer);
return 0;
}
문제를 꼼꼼하게 읽기!!
아무와도 친분이 없을 때 본인을 최고라고 생각한다는 조건을 빼먹어 한 번 틀렸음..