나만 안되는 연애

· 백준
코드#include #include #include #include using namespace std;int n, m, lst[1003], u, v, d, cnt, res;char uv[1003]; // 대학교 성별 저장vector>> adj; // 길 저장// 유니온 파인드 for 크루스칼int find(int x) { if (x == lst[x]) return x; return lst[x] = find(lst[x]);}void merge(int x, int y) { x = find(x); y = find(y); if (x > y) lst[x] = y; else lst[y] = x;}// 비용 순 정렬bool cmp(pair> a, pair> b) { return a.first > n >> m; fo..
· 백준
코드 # 모든 대학교로 이동 가능해야한다 -> 신장 트리 # 최소 비용 -> 최소 신장 트리 # 크루스칼 알고리즘 이용 import sys input = sys.stdin.readline def find(a, lst): if a != lst[a]: lst[a] = find(lst[a],lst) return lst[a] def union(a,b,lst): a = find(a, lst) b = find(b, lst) if a < b: lst[b] = a else: lst[a] = b n, m = map(int, input().split()) school = ['x', *input().rstrip().split()] # 인덱싱을 쉽게 하기 위해 'x'추가 parent = [i for i in range(n+1..