結果
| 問題 |
No.408 五輪ピック
|
| コンテスト | |
| ユーザー |
tossy
|
| 提出日時 | 2016-08-07 10:35:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 5,000 ms |
| コード長 | 1,586 bytes |
| コンパイル時間 | 2,959 ms |
| コンパイル使用メモリ | 94,412 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-07 07:07:45 |
| 合計ジャッジ時間 | 3,081 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second
#define INF 2147483600
#define N 20000
#define M 50000
typedef pair<int, int> P;
vector<int> g[N];
vector<int> len2[N];
P edg[M];
int main(){
int n,m;
cin>>n>>m;
rep(i,m){
int a,b;
scanf("%d %d", &a, &b);
a--;b--;
g[a].pb(b);
g[b].pb(a);
edg[i]=mp(a,b);
}
rep(i, g[0].size()){
int mid = g[0][i];
rep(j, g[mid].size()){
int tgt = g[mid][j];
// 0->mid->tgt
if(tgt==0) continue;
len2[tgt].pb(mid);
}
}
rep(i, m){
int a[2] = {edg[i].fi, edg[i].se};
bool flg=true;
int keep[2]={-1, -1};
rep(j,2){
int sz = len2[a[j]].size();
if(sz>=3) continue;
else if(sz==2){
rep(k,2)if(len2[a[j]][k] == a[!j]){
keep[j] = len2[a[j]][!k];
}
}
else if(sz==1){
if(len2[a[j]][0]==a[!j]) flg=false;
else keep[j] = len2[a[j]][0];
}
else if(sz==0) flg=false;
}
if(!flg) continue;
if(keep[0]!=-1 && keep[1]!=-1 && keep[0]==keep[1]) continue;
cout<<"YES"<<endl;
return 0;
}
cout<<"NO"<<endl;
return 0;
}
tossy