結果

問題 No.2346 Replace!!
ユーザー kotatsugame
提出日時 2023-06-09 23:55:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 497 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 63,492 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-02 06:14:58
合計ジャッジ時間 3,902 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 36 WA * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
int N,A[5000],B[5000];
bool vis[5000];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	for(;T--;)
	{
		cin>>N;
		for(int i=0;i<N;i++)cin>>A[i],A[i]--;
		for(int i=0;i<N;i++)cin>>B[i],B[i]--;
		bool ok=true;
		for(int i=0;i<N;i++)
		{
			int u=A[i];
			for(int j=0;j<N;j++)vis[j]=false;
			while(!vis[u])
			{
				vis[u]=true;
				u=A[u];
			}
			if(!vis[B[i]])ok=false;
		}
		cout<<(ok?"Yes\n":"No\n");
	}
}
0