[Softeer] 우물 안 개구리

CHAEN·2022년 9월 11일
0

problem solving

목록 보기
31/33

문제

접근 방법

  • 그래프..? 인가?

나의 풀이 - C++

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

문제를 꼼꼼하게 읽기!!
아무와도 친분이 없을 때 본인을 최고라고 생각한다는 조건을 빼먹어 한 번 틀렸음..

profile
공부중입니다

0개의 댓글

Powered by GraphCDN, the GraphQL CDN