結果

問題 No.408 五輪ピック
ユーザー どららどらら
提出日時 2016-08-06 01:06:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 95 ms / 5,000 ms
コード長 1,539 bytes
コンパイル時間 1,824 ms
コンパイル使用メモリ 90,284 KB
実行使用メモリ 9,744 KB
最終ジャッジ日時 2023-08-06 21:41:14
合計ジャッジ時間 3,427 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 38 ms
5,644 KB
testcase_06 AC 26 ms
6,480 KB
testcase_07 AC 35 ms
6,312 KB
testcase_08 AC 25 ms
4,860 KB
testcase_09 AC 26 ms
5,364 KB
testcase_10 AC 24 ms
5,728 KB
testcase_11 AC 22 ms
5,540 KB
testcase_12 AC 38 ms
6,228 KB
testcase_13 AC 35 ms
5,512 KB
testcase_14 AC 9 ms
4,688 KB
testcase_15 AC 59 ms
6,612 KB
testcase_16 AC 39 ms
5,228 KB
testcase_17 AC 37 ms
5,408 KB
testcase_18 AC 41 ms
5,940 KB
testcase_19 AC 45 ms
6,444 KB
testcase_20 AC 14 ms
5,388 KB
testcase_21 AC 8 ms
4,768 KB
testcase_22 AC 25 ms
6,444 KB
testcase_23 AC 95 ms
9,744 KB
testcase_24 AC 44 ms
7,852 KB
testcase_25 AC 51 ms
7,280 KB
testcase_26 AC 51 ms
7,096 KB
testcase_27 AC 53 ms
7,236 KB
testcase_28 AC 35 ms
6,424 KB
testcase_29 AC 35 ms
6,532 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int depth[20005];
vector<int> v[20005];
int A[50005],B[50005];
map<int,map<int,int> > memo;

int main(){
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  rep(i,M){
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
    A[i] = a;
    B[i] = b;
  }

  rep(i,v[1].size()){
    int a = v[1][i];
    rep(j,v[a].size()){
      int b = v[a][j];
      if(b == 1) continue;
      memo[b][a] = 1;
    }
  }

  bool ret = false;
  rep(i,M){
    int szA = memo[A[i]].size();
    if(memo[A[i]].count(B[i])>0) szA--;
    int szB = memo[B[i]].size();
    if(memo[B[i]].count(A[i])>0) szB--;

    if(szA == szB && szA == 1){
      map<int,int> cnt;
      FOR(it,memo[A[i]]){
        cnt[it->first]++;
      }
      FOR(it,memo[B[i]]){
        cnt[it->first]++;
      }
      FOR(it,cnt){
        if(it->second == 1) ret = true;
      }
    }
    else if(szA>0 && szB>0 && 2<=max(szA, szB)){
      ret = true;
    }
  }

  
  if(ret) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

0