💻 문제 풀이 : C++
#include <iostream>
#include <vector>
using namespace std;
struct Client {
int isTop;
int weight;
int isNoFriend;
};
int main()
{
int N, M;
cin >> N >> M;
vector<Client> v;
v.push_back({ 0, 0 });
for (int i = 1; i <= N; i++)
{
int weight;
cin >> weight;
v.push_back({0, weight, 1});
}
for (int i = 0; i < M; i++)
{
int from, to;
cin >> from >> to;
if (v[from].weight > v[to].weight)
{
if (v[from].isNoFriend == 1)
v[from].isTop = 1;
v[to].isTop = 0;
v[from].isNoFriend = 0;
v[to].isNoFriend = 0;
}
else if(v[from].weight < v[to].weight)
{
v[from].isTop = 0;
if(v[to].isNoFriend == 1)
v[to].isTop = 1;
v[from].isNoFriend = 0;
v[to].isNoFriend = 0;
}
else {
v[from].isTop = 0;
v[to].isTop = 0;
v[from].isNoFriend = 0;
v[to].isNoFriend = 0;
}
}
int cntClient = 0;
for (int i = 1; i < v.size(); i++) {
if (v[i].isTop == 1 || v[i].isNoFriend == 1)
cntClient++;
}
cout << cntClient;
}
💻 문제 풀이 : Python3
import sys
N, M = map(int, sys.stdin.readline().split())
W = list(map(int, sys.stdin.readline().split()))
isBest = [True] * N
cnt = 0
for _ in range(M):
A, B = map(int, sys.stdin.readline().split())
if W[A-1] > W[B-1]:
isBest[B-1] = False
elif W[A-1] < W[B-1]:
isBest[A-1] = False
else:
isBest[A-1] = False
isBest[B-1] = False
for member in isBest:
if member == True:
cnt += 1
print(cnt)
📌 memo 😊