ps:problems:boj:8096
Monochromatic Triangles
ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 8096 |
문제명 | Monochromatic Triangles |
레벨 | 플래티넘 4 |
분류 |
그래프, 조합론 |
시간복잡도 | O(E) |
인풋사이즈 | E<=250,000 |
사용한 언어 | Python 3.13 |
제출기록 | 38272KB / 88ms |
최고기록 | 84ms |
해결날짜 | 2025/09/11 |
풀이
- 시간복잡도는 O(|E|).
코드
"""Solution code for "BOJ 8096. Monochromatic Triangles".
- Problem link: https://www.acmicpc.net/problem/8096
- Solution link: http://www.teferi.net/ps/problems/boj/8096
Tags: [math]
"""
import math
import sys
from teflib import graph as tgraph
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
def main():
n = int(sys.stdin.readline())
m = int(sys.stdin.readline())
graph = tgraph.create_graph_from_input(n, m)
print(count_3_cycle_or_3_independent_set(graph))
if __name__ == '__main__':
main()
ps/problems/boj/8096.txt · 마지막으로 수정됨: 2025/09/11 14:07 저자 teferi
토론