結果

問題 No.2319 Friends+
ユーザー kotatsugamekotatsugame
提出日時 2023-05-26 22:09:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,022 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 83,888 KB
実行使用メモリ 21,604 KB
最終ジャッジ日時 2023-08-26 11:49:34
合計ジャッジ時間 17,215 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,100 KB
testcase_01 AC 2 ms
4,792 KB
testcase_02 AC 886 ms
16,988 KB
testcase_03 AC 781 ms
17,032 KB
testcase_04 AC 729 ms
16,984 KB
testcase_05 AC 738 ms
16,980 KB
testcase_06 AC 856 ms
16,988 KB
testcase_07 AC 187 ms
17,700 KB
testcase_08 AC 190 ms
17,704 KB
testcase_09 AC 191 ms
17,612 KB
testcase_10 AC 195 ms
17,644 KB
testcase_11 AC 203 ms
17,656 KB
testcase_12 AC 3 ms
4,916 KB
testcase_13 AC 3 ms
4,872 KB
testcase_14 AC 3 ms
5,112 KB
testcase_15 AC 3 ms
5,108 KB
testcase_16 AC 3 ms
4,980 KB
testcase_17 AC 2 ms
4,760 KB
testcase_18 AC 80 ms
9,016 KB
testcase_19 AC 152 ms
17,864 KB
testcase_20 AC 145 ms
16,124 KB
testcase_21 AC 204 ms
15,024 KB
testcase_22 AC 154 ms
16,984 KB
testcase_23 AC 149 ms
17,636 KB
testcase_24 AC 153 ms
17,604 KB
testcase_25 AC 153 ms
17,696 KB
testcase_26 AC 150 ms
17,564 KB
testcase_27 AC 150 ms
17,728 KB
testcase_28 AC 145 ms
17,416 KB
testcase_29 AC 144 ms
17,152 KB
testcase_30 AC 145 ms
16,712 KB
testcase_31 AC 142 ms
15,952 KB
testcase_32 AC 230 ms
15,028 KB
testcase_33 AC 179 ms
13,120 KB
testcase_34 AC 118 ms
11,648 KB
testcase_35 AC 102 ms
10,460 KB
testcase_36 AC 252 ms
17,536 KB
testcase_37 TLE -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<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];
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