結果

問題 No.2319 Friends+
ユーザー kotatsugamekotatsugame
提出日時 2023-05-26 22:12:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,535 ms / 3,000 ms
コード長 1,149 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 84,868 KB
実行使用メモリ 91,840 KB
最終ジャッジ日時 2023-08-26 11:56:00
合計ジャッジ時間 21,384 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,952 KB
testcase_01 AC 3 ms
4,956 KB
testcase_02 AC 1,141 ms
19,128 KB
testcase_03 AC 1,046 ms
19,268 KB
testcase_04 AC 964 ms
19,244 KB
testcase_05 AC 1,047 ms
19,256 KB
testcase_06 AC 1,114 ms
19,060 KB
testcase_07 AC 179 ms
17,288 KB
testcase_08 AC 187 ms
17,388 KB
testcase_09 AC 192 ms
17,280 KB
testcase_10 AC 188 ms
17,472 KB
testcase_11 AC 176 ms
17,300 KB
testcase_12 AC 3 ms
5,068 KB
testcase_13 AC 3 ms
5,036 KB
testcase_14 AC 3 ms
5,036 KB
testcase_15 AC 3 ms
5,036 KB
testcase_16 AC 3 ms
5,044 KB
testcase_17 AC 3 ms
4,900 KB
testcase_18 AC 90 ms
10,968 KB
testcase_19 AC 141 ms
17,036 KB
testcase_20 AC 129 ms
15,980 KB
testcase_21 AC 168 ms
14,980 KB
testcase_22 AC 147 ms
16,596 KB
testcase_23 AC 142 ms
17,236 KB
testcase_24 AC 133 ms
17,208 KB
testcase_25 AC 134 ms
17,172 KB
testcase_26 AC 133 ms
17,340 KB
testcase_27 AC 132 ms
17,176 KB
testcase_28 AC 132 ms
17,044 KB
testcase_29 AC 133 ms
16,804 KB
testcase_30 AC 132 ms
16,432 KB
testcase_31 AC 127 ms
15,816 KB
testcase_32 AC 186 ms
14,704 KB
testcase_33 AC 158 ms
13,344 KB
testcase_34 AC 123 ms
12,280 KB
testcase_35 AC 120 ms
11,756 KB
testcase_36 AC 516 ms
91,840 KB
testcase_37 AC 1,325 ms
17,016 KB
testcase_38 AC 147 ms
17,192 KB
testcase_39 AC 152 ms
17,180 KB
testcase_40 AC 176 ms
17,192 KB
testcase_41 AC 221 ms
17,204 KB
testcase_42 AC 321 ms
17,208 KB
testcase_43 AC 481 ms
17,560 KB
testcase_44 AC 825 ms
17,780 KB
testcase_45 AC 1,535 ms
18,304 KB
testcase_46 AC 1,413 ms
16,240 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;
		}
		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[X]];
				++EX[v][P[Y]];
			}
			P[X]=P[Y];
		}
	}
}
0