ps:problems:boj:8907
네온 사인
ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 8907 |
문제명 | 네온 사인 |
레벨 | 플래티넘 4 |
분류 |
그래프, 조합론 |
시간복잡도 | O(T*V^2) |
인풋사이즈 | T<=? , V<=1000 |
사용한 언어 | Python 3.13 |
제출기록 | 58216KB / 1676ms |
최고기록 | 1676ms |
해결날짜 | 2025/09/11 |
풀이
- 시간복잡도는 O(|E|) = O(|V|^2).
코드
"""Solution code for "BOJ 8907. 네온 사인".
- Problem link: https://www.acmicpc.net/problem/8907
- Solution link: http://www.teferi.net/ps/problems/boj/8907
Tags: [math]
"""
import math
import sys
from teflib import psutils
@psutils.run_n_times
def main():
N = int(sys.stdin.readline())
degs = [0] * N
for u in range(N - 1):
colors = sys.stdin.readline().split()
degs[u] += colors.count('1')
for v, c in enumerate(colors, start=u + 1):
if c == '1':
degs[v] += 1
answer = math.comb(N, 3) - sum(d * (N - 1 - d) for d in degs) // 2
print(answer)
if __name__ == '__main__':
main()
ps/problems/boj/8907.txt · 마지막으로 수정됨: 2025/09/11 14:26 저자 teferi
토론