사용자 도구

사이트 도구


ps:problems:boj:1707

이분 그래프

ps
링크acmicpc.net/…
출처BOJ
문제 번호1707
문제명이분 그래프
레벨골드 4
분류

이분 그래프

시간복잡도O(T*(V+E))
인풋사이즈T<=5, V<=20,000, E<=200,000
사용한 언어Python
제출기록69428KB / 1204ms
최고기록1000ms
해결날짜2023/04/04

풀이

  • 그래프가 이분 그래프인지만 판별하면 되는 기본 문제. 시간복잡도는 O(V+E)

코드

"""Solution code for "BOJ 1707. 이분 그래프".

- Problem link: https://www.acmicpc.net/problem/1707
- Solution link: http://www.teferi.net/ps/problems/boj/1707
"""

import sys
from teflib import graph as tgraph


def main():
    K = int(sys.stdin.readline())
    for _ in range(K):
        V, E = [int(x) for x in sys.stdin.readline().split()]
        graph = tgraph.create_graph_from_input(V, E)

        try:
            tgraph.two_coloring(graph)
            print('YES')
        except ValueError:
            print('NO')


if __name__ == '__main__':
    main()

토론

댓글을 입력하세요:
X F M U P
 
ps/problems/boj/1707.txt · 마지막으로 수정됨: 2023/04/04 14:54 저자 teferi