사용자 도구

사이트 도구


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

풀이

코드

"""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()

토론

댓글을 입력하세요:
M T X P L
 
ps/problems/boj/8907.txt · 마지막으로 수정됨: 2025/09/11 14:26 저자 teferi