結果

問題 No.408 五輪ピック
ユーザー fiordfiord
提出日時 2016-08-08 14:58:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 838 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 69,036 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-04-24 22:05:12
合計ジャッジ時間 2,017 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 14 ms
5,632 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 10 ms
5,376 KB
testcase_11 AC 8 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 6 ms
5,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 9 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 RE -
testcase_23 AC 16 ms
6,016 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 16 ms
5,504 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
using namespace std;
const int N=20000;
vector<int> edge[N];
set<int> list[N];
void dfs(int cur,int parent,int state){
	if(state==2){
		list[cur].insert(parent);
		return;
	}
	for(int i=0;i<edge[cur].size();i++){
		if(parent==edge[cur][i])	continue;
		dfs(edge[cur][i],cur,state+1);
	}
	return;
}
int main(){
	int n,m;	cin>>n>>m;
	vector<int> a(m),b(m);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];	a[i]--;	b[i]--;
		edge[a[i]].push_back(b[i]);
		edge[b[i]].push_back(a[i]);
	}
	dfs(0,0,0);
	for(int i=0;i<m;i++){
		int numa=list[a[i]].size();
		int numb=list[b[i]].size();
		if(numa==0||numb==0)	continue;
		if(numa==1&&numb==1){
			int aa=*list[a[i]].begin();
			int bb=*list[b[i]].begin();
			if(aa==bb)	continue;
		}
		cout<<"YES"<<endl;
		return 0;
	}
	cout<<"NO"<<endl;
	return 0;
}
0