結果

問題 No.408 五輪ピック
ユーザー CZS_AK_IOI2025
提出日時 2025-04-28 21:38:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,294 bytes
コンパイル時間 2,207 ms
コンパイル使用メモリ 196,684 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-04-28 21:38:52
合計ジャッジ時間 3,785 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
#define maxn 20005
namespace CZS_Office{
	inline int read(){
		int x=0,f=1;
		char ch=getchar();
		while(ch<'0'||ch>'9'){
			if(ch=='-')f=-1;
			ch=getchar();
		}
		while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
		return x*f;
	}
	inline void write(int x){
		if(x<0){
			putchar('-');
			x=-x;
		}
		if(x>9)write(x/10);
		putchar(x%10+'0');
		return;
	}
}
using namespace std;
using namespace CZS_Office;
int n,m,cnt[maxn];bool NTT[maxn],gogoCZS[maxn];
vector<int>edge[maxn],bridge[maxn];
inline bool check(int c,int d){
	if(c==1||c==d||d==1)return 0;
	if(cnt[c]>=3||cnt[d]>=3)return 1;
	vector<int>cur;
	for(auto b:bridge[c]){
		if(b==1||b==d||b==c)continue;
		for(auto e:bridge[d]){
			if(e==1||e==b||e==c||e==d)continue;
			return 1;
		}
	}
	return 0;
}
signed main(){
	n=read();m=read();
	for(int i=1;i<=m;++i){
		int u=read(),v=read();
		edge[u].push_back(v);
		edge[v].push_back(u);
		if(u==1)gogoCZS[v]=1;
		if(v==1)gogoCZS[u]=1;
	}
	for(auto b:edge[1]){
		for(auto c:edge[b]){
			if(b==c)continue;
			++cnt[c];NTT[c]=1;
			bridge[c].push_back(b);
		}
	}
	for(int c=1;c<=n;++c){
		if(!NTT[c])continue;
		for(auto d:edge[c]){
			if(!NTT[d])continue;
			if(check(c,d)){
				cout<<"YES";
				return 0;
			}
		}
	}
	cout<<"NO";
	return 0;
}
0