結果
問題 | No.1817 Reversed Edges |
ユーザー |
![]() |
提出日時 | 2022-01-21 22:19:13 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,091 bytes |
コンパイル時間 | 366 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 350,888 KB |
最終ジャッジ日時 | 2024-11-26 00:48:40 |
合計ジャッジ時間 | 21,845 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 TLE * 2 |
ソースコード
import itertools as iterimport collections as collimport heapq as hqimport bisect as bisfrom decimal import Decimal as decfrom copy import deepcopy as dcopyimport mathimport syssys.setrecursionlimit(10 ** 6)def input():return sys.stdin.readline().rstrip()def getN():return int(sys.stdin.readline())def getNs():return map(int,sys.stdin.readline().split())def getList():return list(map(int,sys.stdin.readline().split()))def strinps(n):return [sys.stdin.readline().rstrip() for _ in range(n)]pi = 3.141592653589793mod = 10**9+7MOD = 998244353INF = math.infdx = [1,0,-1,0]; dy = [0,1,0,-1]"""Main Code"""n = getN()route = [[] for _ in [0] * n]d = {}for _ in [0] * (n - 1):a,b = [i - 1 for i in getNs()]route[a].append(b)route[b].append(a)def count(a, b):global dif((a, b) in d):return d[(a, b)]d[(a, b)] = 0for nv in route[b]:if(nv == a):continued[(a, b)] += count(b, nv)d[(a, b)] += (a > b)return d[(a, b)]for i in range(n):#print(d)ans = 0for nv in route[i]:#print((i, nv))ans += count(i, nv)print(ans)