結果
問題 | No.2319 Friends+ |
ユーザー |
![]() |
提出日時 | 2024-08-31 14:29:06 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 878 bytes |
コンパイル時間 | 464 ms |
コンパイル使用メモリ | 82,348 KB |
実行使用メモリ | 434,808 KB |
最終ジャッジ日時 | 2024-08-31 14:29:55 |
合計ジャッジ時間 | 45,836 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 WA * 8 TLE * 4 -- * 9 |
ソースコード
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]={i:0 for i in range(n)}for 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-=1ok=p[x]!=p[y]pp=p[x]np=p[y]if f[x]:ok&=any(p[t]==p[y] for t in e2[x])ok&=c[x][p[y]]!=0else:ok&=any(p[t]==p[y] for t in e[x])if ok:print("Yes")if f[x]==0:for t in e2[x]:c[t][pp]-=1c[t][np]+=1p[x]=p[y]else:print("No")