250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 다대일
- PS
- 연결리스트
- 유니크제약조건
- exclusive lock
- 스토어드 프로시저
- 힙
- execute
- 낙관적락
- 데코레이터
- BOJ
- 지연로딩
- querydsl
- shared lock
- 즉시로딩
- 백트래킹
- SQL프로그래밍
- 일대다
- 다대다
- eager
- fetch
- 동적sql
- 스프링 폼
- JPQL
- dfs
- 이진탐색
- FetchType
- 연관관계
- 비관적락
- CHECK OPTION
Archives
- Today
- Total
흰 스타렉스에서 내가 내리지
[BOJ] (GRAPH) 1707번 이분 그래프 본문
728x90
이분그래프에 대해 공부한 적이 있어서 금방 풀었던 문제.
from collections import deque
def main():
for _ in range(int(input())):
V, E = map(int, input().split())
graph = [[] for __ in range(V+1)]
for ___ in range(E):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
if isBipartite(graph):
print('YES')
else:
print('NO')
def isBipartite(graph):
vertices = len(graph)
colors = [None] * vertices
visited = [False] * vertices
for i in range(1, vertices):
q = deque()
q.append(i)
while q:
now = q.popleft()
if visited[now]:
continue
if colors[now] == None:
colors[now] = 0
now_color = colors[now]
visited[now] = True
for v in graph[now]:
if colors[v] == now_color:
return False
colors[v] = 1- now_color
q.append(v)
return True
main()
https://www.acmicpc.net/problem/1707
1707번: 이분 그래프
입력은 여러 개의 테스트 케이스로 구성되어 있는데, 첫째 줄에 테스트 케이스의 개수 K가 주어진다. 각 테스트 케이스의 첫째 줄에는 그래프의 정점의 개수 V와 간선의 개수 E가 빈 칸을 사이에
www.acmicpc.net
'Problem Solving' 카테고리의 다른 글
[BOJ] (DFS) 15658번 연산자 끼워넣기 (2) (0) | 2022.02.27 |
---|---|
[BOJ] (BFS)7576번 토마토 (0) | 2022.02.25 |
[BOJ] (DP) 1149번 RGB거리 (0) | 2022.02.17 |
[BOJ] (ALGO) 14003번 가장 긴 증가하는 부분 수열 5 ★ (0) | 2022.02.06 |
[BOJ] (BIT, BF)14391번 종이 조각 ★★ (0) | 2022.02.06 |