xxxxxxxxxx
from collections import deque
N=int(input())
b=list(map(int,input().split()))
c=list(input().split())
M=int(input())
g=[[] for _ in range(N)]
for i in range(M):
x,y=map(int,input().split())
g[x-1].append(y-1)
g[y-1].append(x-1)
Q=deque()
check=set()
ans=0
for x in range(N):
if x in check:
continue
bright,color=b[x],c[x]
Q.append(x)
check.add(x)
while len(Q):
now=Q.popleft()
for i in range(len(g[now])):
nex=g[now][i]
if nex in check:
continue
if b[nex]>bright:
bright=b[nex]
color=c[nex]
Q.append(nex)
check.add(nex)
if color=='R':
ans+=1
print(ans)
提出日時 | |
ユーザー | ![]() |
言語 | Python3 (CPython 3.8) |
結果 | AC |
実行時間 | 256 ms |
メモリ | 318880 kb |
テストケース名 | 結果 | 実行時間 | メモリ |
---|---|---|---|
handmade1.txt | AC | 26 ms | 318880 kb |
handmade2.txt | AC | 28 ms | 318880 kb |
random1.txt | AC | 26 ms | 318880 kb |
random10.txt | AC | 252 ms | 318880 kb |
random11.txt | AC | 25 ms | 318880 kb |
random2.txt | AC | 16 ms | 318880 kb |
random3.txt | AC | 17 ms | 318880 kb |
random4.txt | AC | 76 ms | 318880 kb |
random5.txt | AC | 21 ms | 318880 kb |
random6.txt | AC | 148 ms | 318880 kb |
random7.txt | AC | 114 ms | 318880 kb |
random8.txt | AC | 251 ms | 318880 kb |
random9.txt | AC | 256 ms | 318880 kb |
sample1.txt | AC | 14 ms | 318880 kb |
sample2.txt | AC | 14 ms | 318880 kb |