結果

問題 No.2319 Friends+
ユーザー kotatsugamekotatsugame
提出日時 2023-05-26 22:10:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,083 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 85,888 KB
実行使用メモリ 17,504 KB
最終ジャッジ日時 2023-08-26 11:51:57
合計ジャッジ時間 30,630 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,140 KB
testcase_01 AC 3 ms
5,020 KB
testcase_02 AC 1,231 ms
16,396 KB
testcase_03 AC 1,156 ms
16,388 KB
testcase_04 AC 1,030 ms
16,508 KB
testcase_05 AC 1,057 ms
16,400 KB
testcase_06 AC 1,182 ms
16,368 KB
testcase_07 AC 260 ms
17,172 KB
testcase_08 AC 242 ms
17,256 KB
testcase_09 AC 246 ms
17,232 KB
testcase_10 AC 242 ms
17,264 KB
testcase_11 AC 255 ms
17,212 KB
testcase_12 AC 3 ms
5,216 KB
testcase_13 AC 3 ms
5,024 KB
testcase_14 AC 3 ms
5,024 KB
testcase_15 AC 3 ms
5,008 KB
testcase_16 AC 4 ms
5,036 KB
testcase_17 AC 3 ms
4,932 KB
testcase_18 AC 100 ms
11,008 KB
testcase_19 AC 179 ms
17,160 KB
testcase_20 AC 155 ms
16,032 KB
testcase_21 AC 248 ms
15,040 KB
testcase_22 AC 177 ms
16,536 KB
testcase_23 AC 202 ms
17,244 KB
testcase_24 AC 176 ms
17,244 KB
testcase_25 AC 174 ms
17,200 KB
testcase_26 AC 170 ms
17,236 KB
testcase_27 AC 169 ms
17,144 KB
testcase_28 AC 161 ms
17,008 KB
testcase_29 AC 173 ms
16,836 KB
testcase_30 AC 172 ms
16,424 KB
testcase_31 AC 164 ms
16,028 KB
testcase_32 AC 308 ms
14,780 KB
testcase_33 AC 240 ms
13,344 KB
testcase_34 AC 147 ms
12,180 KB
testcase_35 AC 130 ms
11,496 KB
testcase_36 AC 328 ms
16,636 KB
testcase_37 TLE -
testcase_38 AC 203 ms
17,208 KB
testcase_39 AC 226 ms
17,180 KB
testcase_40 AC 278 ms
17,184 KB
testcase_41 AC 391 ms
17,180 KB
testcase_42 AC 580 ms
17,256 KB
testcase_43 AC 956 ms
17,200 KB
testcase_44 AC 1,722 ms
17,336 KB
testcase_45 TLE -
testcase_46 AC 2,950 ms
15,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
//#include<map>
#include<unordered_map>
using namespace std;
int N,M;
int P[20000];
int U[2<<17],V[2<<17],deg[20000];
vector<int>G[20000];
//map<int,int>EX[20000];
unordered_map<int,int>EX[20000];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M;
	for(int i=0;i<N;i++)
	{
		cin>>P[i];
		P[i]--;
	}
	for(int i=0;i<M;i++)
	{
		cin>>U[i]>>V[i];
		U[i]--,V[i]--;
		if(U[i]==V[i])continue;
		deg[U[i]]++;
		deg[V[i]]++;
	}
	for(int i=0;i<M;i++)
	{
		if(U[i]==V[i])continue;
		if(make_pair(deg[U[i]],U[i])>make_pair(deg[V[i]],V[i]))swap(U[i],V[i]);
		G[U[i]].push_back(V[i]);
		EX[V[i]][P[U[i]]]++;
	}
	int Q;cin>>Q;
	for(;Q--;)
	{
		int X,Y;cin>>X>>Y;X--,Y--;
		if(P[X]==P[Y])
		{
			cout<<"No\n";
			continue;
		}
		bool fn=false;
		{
			auto it=EX[X].find(P[Y]);
			if(it!=EX[X].end()&&it->second)fn=true;
		}
		for(int v:G[X])if(P[v]==P[Y])fn=true;
		if(!fn)cout<<"No\n";
		else
		{
			cout<<"Yes\n";
			for(int v:G[X])
			{
				if(!--EX[v][P[X]])EX[v].erase(EX[v].find(P[X]));
				EX[v][P[Y]]++;
			}
			P[X]=P[Y];
		}
	}
}
0