結果
問題 | No.2319 Friends+ |
ユーザー |
![]() |
提出日時 | 2024-08-31 15:38:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,426 ms / 3,000 ms |
コード長 | 885 bytes |
コンパイル時間 | 442 ms |
コンパイル使用メモリ | 82,552 KB |
実行使用メモリ | 191,340 KB |
最終ジャッジ日時 | 2024-08-31 15:38:46 |
合計ジャッジ時間 | 37,975 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 45 |
ソースコード
n,m=map(int,input().split())p=list(map(int,input().split()))for i in range(n):p[i]-=1B=448e=[[] for i in range(n)]for i in range(m):a,b=map(int,input().split())a-=1b-=1e[a]+=[b]e[b]+=[a]f=[len(e[i])>=B for i in range(n)]e2=[[] for i in range(n)]for s in range(n):for t in e[s]:if f[t]==1:e2[s]+=[t]c=[[] for i in range(n)]for s in range(n):if f[s]==1:c[s]=[0]*nfor s in range(n):if f[s]==0:for t in e2[s]:c[t][p[s]]+=1Q=int(input())for _ in range(Q):x,y=map(int,input().split())x-=1y-=1if p[x]==p[y]:print("No")continueok=0if f[x]:for t in e2[x]:ok|=p[t]==p[y]ok|=c[x][p[y]]!=0else:for t in e[x]:ok|=p[t]==p[y]if ok:print("Yes")if f[x]==0:for t in e2[x]:c[t][p[x]]-=1c[t][p[y]]+=1p[x]=p[y]else:print("No")