結果

問題 No.408 五輪ピック
ユーザー どららどらら
提出日時 2016-08-06 01:07:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 1,521 bytes
コンパイル時間 924 ms
コンパイル使用メモリ 95,944 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-04-24 16:11:20
合計ジャッジ時間 2,822 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 AC 38 ms
5,504 KB
testcase_06 AC 25 ms
6,400 KB
testcase_07 AC 35 ms
6,272 KB
testcase_08 AC 25 ms
5,376 KB
testcase_09 AC 26 ms
5,376 KB
testcase_10 AC 23 ms
5,760 KB
testcase_11 AC 22 ms
5,504 KB
testcase_12 AC 38 ms
6,016 KB
testcase_13 AC 35 ms
5,376 KB
testcase_14 AC 9 ms
5,376 KB
testcase_15 AC 54 ms
6,784 KB
testcase_16 AC 39 ms
5,376 KB
testcase_17 AC 37 ms
5,376 KB
testcase_18 AC 41 ms
5,760 KB
testcase_19 AC 46 ms
6,272 KB
testcase_20 AC 14 ms
5,376 KB
testcase_21 AC 8 ms
5,376 KB
testcase_22 AC 23 ms
6,400 KB
testcase_23 AC 79 ms
9,984 KB
testcase_24 AC 39 ms
7,936 KB
testcase_25 AC 48 ms
7,296 KB
testcase_26 AC 50 ms
7,168 KB
testcase_27 AC 52 ms
7,168 KB
testcase_28 AC 32 ms
6,400 KB
testcase_29 AC 32 ms
6,400 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 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;

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