結果

問題 No.1745 Selfish Spies 2 (à la Princess' Perfectionism)
ユーザー kotatsugamekotatsugame
提出日時 2021-11-18 20:31:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,148 ms / 5,000 ms
コード長 2,589 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 40,476 KB
最終ジャッジ日時 2023-08-27 14:19:51
合計ジャッジ時間 10,194 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 12 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 51 ms
7,404 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 5 ms
4,380 KB
testcase_31 AC 5 ms
4,380 KB
testcase_32 AC 5 ms
4,380 KB
testcase_33 AC 50 ms
7,156 KB
testcase_34 AC 50 ms
7,176 KB
testcase_35 AC 51 ms
7,020 KB
testcase_36 AC 52 ms
7,088 KB
testcase_37 AC 51 ms
7,216 KB
testcase_38 AC 50 ms
7,304 KB
testcase_39 AC 25 ms
5,428 KB
testcase_40 AC 40 ms
6,820 KB
testcase_41 AC 41 ms
6,788 KB
testcase_42 AC 87 ms
10,808 KB
testcase_43 AC 131 ms
13,504 KB
testcase_44 AC 179 ms
16,248 KB
testcase_45 AC 710 ms
26,792 KB
testcase_46 AC 631 ms
26,792 KB
testcase_47 AC 433 ms
39,732 KB
testcase_48 AC 440 ms
39,732 KB
testcase_49 AC 219 ms
11,184 KB
testcase_50 AC 211 ms
11,180 KB
testcase_51 AC 77 ms
6,436 KB
testcase_52 AC 56 ms
9,612 KB
testcase_53 AC 54 ms
9,620 KB
testcase_54 AC 211 ms
15,780 KB
testcase_55 AC 206 ms
15,856 KB
testcase_56 AC 1,148 ms
16,212 KB
testcase_57 AC 421 ms
40,280 KB
testcase_58 AC 415 ms
40,476 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:106:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
  106 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
struct bimatch{
	int n;
	vector<vector<int> >G;
	vector<int>match;
	vector<bool>used;
	bimatch(int _n=0):n(_n),G(n),match(n),used(n){}
	void add_edge(int u,int v)
	{
		G[u].push_back(v);
		G[v].push_back(u);
	}
	bool dfs(int v)
	{
		used[v]=true;
		for(int u:G[v])
		{
			int w=match[u];
			if(w<0||!used[w]&&dfs(w))
			{
				match[v]=u;
				match[u]=v;
				return true;
			}
		}
		return false;
	}
	int count()
	{
		int ans=0;
		bool flag=true;
		fill(match.begin(),match.end(),-1);
		while(flag)
		{
			flag=false;
			fill(used.begin(),used.end(),false);
			for(int v=0;v<n;v++)if(match[v]<0&&dfs(v))ans++,flag=true;
		}
		return ans;
	}
};
//Strongly Connected Components
#include<vector>
struct SCC{
	int n;
	vector<int>comp,order;
	vector<bool>used;
	vector<vector<int> >G,RG;
	SCC(int _n=0):n(_n),comp(_n,-1),used(_n,false),G(_n),RG(_n){}
	void add_edge(int from,int to)
	{
		G[from].push_back(to);
		RG[to].push_back(from);
	}
	void copy(const vector<vector<int> >&H)
	{
		for(int i=0;i<H.size();i++)
		{
			for(int j=0;j<H[i].size();j++)
			{
				G[i].push_back(H[i][j]);
				RG[H[i][j]].push_back(i);
			}
		}
	}
	int operator[](int u)const{return comp[u];}
	void dfs(int u)
	{
		used[u]=true;
		for(int i=0;i<G[u].size();i++)if(!used[G[u][i]])dfs(G[u][i]);
		order.push_back(u);
	}
	void rdfs(int u,int cnt)
	{
		comp[u]=cnt;
		for(int i=0;i<RG[u].size();i++)if(comp[RG[u][i]]==-1)rdfs(RG[u][i],cnt);
	}
	int build()
	{
		for(int i=0;i<n;i++)if(!used[i])dfs(i);
		int cnt=0;
		for(int i=n-1;i>=0;i--)if(comp[order[i]]==-1)rdfs(order[i],cnt++);
		return cnt;
	}
	int build(vector<vector<int> >&H)
	{
		int ret=build();
		H.assign(ret,vector<int>());
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<G[i].size();j++)
			{
				if(comp[i]!=comp[G[i][j]])
					H[comp[i]].push_back(comp[G[i][j]]);
			}
		}
		return ret;
	}
};
int N,M,L;
int U[2<<17],V[2<<17];
bool A[2<<17];
main()
{
	cin>>N>>M>>L;
	bimatch P(N+M);
	for(int i=0;i<L;i++)
	{
		cin>>U[i]>>V[i];
		U[i]--,V[i]--;
		V[i]+=N;
		P.add_edge(U[i],V[i]);
	}
	P.count();
	SCC Q(N+M+2);
	for(int i=0;i<L;i++)
	{
		if(P.match[U[i]]==V[i])A[i]=true;
		else A[i]=false;
		if(A[i])
		{
			Q.add_edge(U[i],V[i]);
		}
		else
		{
			Q.add_edge(V[i],U[i]);
		}
	}
	for(int i=0;i<N;i++)
	{
		if(P.match[i]==-1)Q.add_edge(i,N+M);
		else Q.add_edge(N+M,i);
	}
	for(int i=0;i<M;i++)
	{
		if(P.match[i+N]==-1)Q.add_edge(N+M+1,i+N);
		else Q.add_edge(i+N,N+M+1);
	}
	Q.build();
	for(int i=0;i<L;i++)
	{
		bool f=A[i]||Q[U[i]]==Q[V[i]];
		cout<<(f?"Yes\n":"No\n");
	}
}
0