結果

問題 No.2319 Friends+
ユーザー kotatsugamekotatsugame
提出日時 2023-05-26 22:11:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,128 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 85,576 KB
実行使用メモリ 17,576 KB
最終ジャッジ日時 2023-08-26 11:53:56
合計ジャッジ時間 29,616 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,944 KB
testcase_01 AC 3 ms
4,928 KB
testcase_02 AC 1,206 ms
16,524 KB
testcase_03 AC 1,116 ms
16,416 KB
testcase_04 AC 1,007 ms
16,440 KB
testcase_05 AC 1,037 ms
16,408 KB
testcase_06 AC 1,121 ms
16,384 KB
testcase_07 AC 253 ms
17,248 KB
testcase_08 AC 238 ms
17,272 KB
testcase_09 AC 254 ms
17,260 KB
testcase_10 AC 253 ms
17,184 KB
testcase_11 AC 249 ms
17,204 KB
testcase_12 AC 4 ms
5,012 KB
testcase_13 AC 3 ms
5,016 KB
testcase_14 AC 4 ms
5,028 KB
testcase_15 AC 3 ms
5,080 KB
testcase_16 AC 4 ms
5,096 KB
testcase_17 AC 3 ms
4,944 KB
testcase_18 AC 103 ms
11,004 KB
testcase_19 AC 187 ms
17,060 KB
testcase_20 AC 165 ms
15,996 KB
testcase_21 AC 244 ms
15,200 KB
testcase_22 AC 189 ms
16,764 KB
testcase_23 AC 195 ms
17,188 KB
testcase_24 AC 181 ms
17,192 KB
testcase_25 AC 181 ms
17,188 KB
testcase_26 AC 177 ms
17,156 KB
testcase_27 AC 180 ms
17,244 KB
testcase_28 AC 167 ms
17,016 KB
testcase_29 AC 173 ms
16,824 KB
testcase_30 AC 164 ms
16,500 KB
testcase_31 AC 156 ms
16,064 KB
testcase_32 AC 309 ms
14,916 KB
testcase_33 AC 241 ms
13,332 KB
testcase_34 AC 149 ms
12,216 KB
testcase_35 AC 132 ms
11,752 KB
testcase_36 AC 325 ms
16,676 KB
testcase_37 AC 2,954 ms
16,628 KB
testcase_38 AC 207 ms
17,216 KB
testcase_39 AC 239 ms
17,204 KB
testcase_40 AC 293 ms
17,200 KB
testcase_41 AC 393 ms
17,200 KB
testcase_42 AC 584 ms
17,196 KB
testcase_43 AC 946 ms
17,288 KB
testcase_44 AC 1,692 ms
17,344 KB
testcase_45 TLE -
testcase_46 TLE -
権限があれば一括ダウンロードができます

ソースコード

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;
		}
		if(!fn)
		{
			for(int v:G[X])if(P[v]==P[Y])
			{
				fn=true;
				break;
			}
		}
		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