Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 19, 2017 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/ee718472cea92481ecb36655225ef06b to your computer and use it in GitHub Desktop.
Save whatalnk/ee718472cea92481ecb36655225ef06b to your computer and use it in GitHub Desktop.
AtCoder ARC #043 B - 最短路問題
def main():
R = 10**9+7
N = int(input())
a = list(map(int, input().split(" ")))
if a[0] != 0:
return 0
amax = max(a)
h = [0] * (amax+1)
for i in a:
h[i] += 1
if h[0] != 1:
return 0
ans = 1
b = 1
for i in h[1:]:
if i == 0:
return 0
ans *= pow(2, i * (i - 1) // 2, R)
ans %= R
ans *= pow(pow(2, b, R) - 1, i, R)
ans %= R
b = i
return ans
if __name__ == '__main__':
print(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment