結果
| 問題 |
No.408 五輪ピック
|
| ユーザー |
|
| 提出日時 | 2016-08-06 01:43:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 5,000 ms |
| コード長 | 2,285 bytes |
| コンパイル時間 | 1,143 ms |
| コンパイル使用メモリ | 105,784 KB |
| 実行使用メモリ | 8,672 KB |
| 最終ジャッジ日時 | 2024-11-07 01:55:48 |
| 合計ジャッジ時間 | 2,592 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
if(p) cout << fixed << setprecision(p) << a << "\n";
else cout << a << "\n";
}
// end of template
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
// source code
int N, M;
cin >> N >> M;
vector<vector<int>> G(N);
vector<set<int>> H(N);
rep(i, M){
int a, b;
cin >> a >> b;
a--, b--;
G[a].pb(b);
G[b].pb(a);
}
vector<int> P(N, 0), Q(N, 0);
for(int v: G[0]){
Q[v] = 1;
// H[0].insert(v), H[v].insert(0);
for(int w: G[v]){
if(w != 0){
P[w] = 1;
H[v].insert(w), H[w].insert(v);
}
}
}
//
// rep(i, H.size()){
// cout << i << ": ";
// for(auto it = H[i].begin(); it != H[i].end(); it++){
// cout << *it << ", ";
// }
// cout << endl;
// }
for(int i = 1; i < N; i++){
for(int j: G[i]){
if(j == 0) continue;
if(P[i] && P[j]){
// cout << i << ", " << j << ": " << H[i].size() << ", " << H[j].size() << endl;
if(H[i].size() == 1 && H[j].size() == 1){
if((*(H[i].begin()) != *(H[j].begin())) && (*(H[i].begin()) != j)){
// cout << "one" << endl;
output("YES", 0);
return 0;
}
}
if(G[i].size() >= 2 && G[j].size() >= 2 && max(H[i].size(), H[j].size()) >= 3){
// cout << "two" << endl;
output("YES", 0);
return 0;
}
}
}
}
output("NO", 0);
return 0;
}