AtCoder Regular Contest 111 - AtCoder
ARC111, A, B, and D were the three questions. Mistake(?) that the caller missed the pre-arrangement.
The RE for C was submitted to C with the wrong code for D.
def main():
N, M = map(int, input().split())
M2 = M * M
doubling = [10 % M2]
for i in range(60):
doubling.append(
(doubling[-1] ** 2) % M2
)
ret = 1
for i in range(60):
if N % 2:
ret *= doubling[i]
ret %= M2
N //= 2
print(ret // M)
def main():
N = int(input())
init_unionfind(400000 + 1)
numEdge = [0] * (400000 + 1)
for _i in range(N):
a, b = map(int, input().split())
ra = find_root(a)
rb = find_root(b)
if ra == rb:
numEdge[ra] += 1
else:
unite(a, b)
rc = find_root(a)
numEdge[rc] = numEdge[ra] + numEdge[rb] + 1
from collections import Counter
ccs = Counter(find_root(a) for a in range(1, 400000 + 1))
ret = 0
for cc in ccs:
V = ccs[cc]
E = numEdge[cc]
if E == V - 1:
ret += V - 1
else:
ret += V
print(ret)
I see. I wonder why.
I looked back at my notes, and they were graphed in a stream of drawing samples and trying to understand them, without going through a particularly clear "realization".
If I dare to put it into words, there is no need to maintain the form of the given sequence, since this problem is not affected by changing the order of the cards, nor by changing the backs of the cards, so there is no need to maintain the form of the given sequence, it's more like having it in a more flexible form!
I'm not sure about C, so skip it and go to D.
python
def main():
_N, M = map(int, input().split())
from collections import defaultdict
edgelist = []
for _i in range(M):
frm, to = map(int, input().split())
edgelist.append((frm - 1, to - 1))
CS = list(map(int, input().split()))
answer = {}
edges = defaultdict(list)
for v1, v2 in edgelist:
if CS[v1] > CS[v2]:
answer[(v1, v2)] = "->"
elif CS[v1] < CS[v2]:
answer[(v1, v2)] = "<-"
else:
edges[v1].append(v2)
edges[v2].append(v1)
for v1, v2 in edgelist:
if (v1, v2) not in answer:
answer[(v1, v2)] = "->"
answer[(v2, v1)] = "<-"
def visit(e):
(v1, v2) = e
for v3 in edges[v2]:
if v3 == v1:
continue
if (v2, v3) in answer:
continue
answer[(v2, v3)] = "->"
answer[(v3, v2)] = "<-"
visit((v2, v3))
visit((v1, v2))
for v1, v2 in edgelist:
print(answer[(v1, v2)])
The heavier luggage should be handed over to the rightful owner in that order! The recipient doesn't have to worry about the weight because it will be in the correct luggage, and the one who gives it to you will exchange it for a lighter one, so you won't have to worry about it afterwards!
E
This page is auto-translated from /nishio/ARC111 using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.