====== 네온 사인 ====== ===== 풀이 ===== * [[ps:tutorial:부분그래프 세기#모두 연결되었거나, 모두 연결되어있지 않은 세 노드 세기]] 참고. * {{myicon>p4}} [[ps:problems:boj:8096]], {{myicon>p4}} [[ps:problems:boj:17275]] 도 동일한 문제이다. * 시간복잡도는 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() {{tag>BOJ ps:problems:boj:플래티넘_4}}