사용자 도구

사이트 도구


ps:problems:boj:17275

부족 전쟁

ps
링크acmicpc.net/…
출처BOJ
문제 번호17275
문제명부족 전쟁
레벨플래티넘 4
분류

그래프, 조합론

시간복잡도O(T*E)
인풋사이즈T<=10, E<=1,000,000
사용한 언어Python 3.13
제출기록77264KB / 3156ms
최고기록1780ms
해결날짜2025/09/11

풀이

코드

"""Solution code for "BOJ 17275. 부족 전쟁".

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

Tags: [math]
"""

import math
import sys
from teflib import graph as tgraph
from teflib import psutils


def count_3_cycle_or_3_independent_set(graph):
    n = len(graph)
    degs = [len(neighbors) for neighbors in graph]
    invalid_set_count = sum(d * (n - 1 - d) for d in degs) // 2
    return math.comb(n, 3) - invalid_set_count


@psutils.run_n_times
def main():
    N, M = [int(x) for x in sys.stdin.readline().split()]
    graph = tgraph.create_graph_from_input(N, M)
    print(count_3_cycle_or_3_independent_set(graph))


if __name__ == '__main__':
    main()

토론

댓글을 입력하세요:
B C J Q Y
 
ps/problems/boj/17275.txt · 마지막으로 수정됨: 2025/09/11 14:18 저자 teferi