結果

問題 No.1610 She Loves Me, She Loves Me Not, ...
ユーザー siman
提出日時 2021-07-22 10:58:25
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,238 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 145,840 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-17 21:11:46
合計ジャッジ時間 2,420 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_N = 5010;

set<int> E[MAX_N];

struct Node {
  int v;
  int cnt;

  Node(int v = -1, int cnt = -1) {
    this->v = v;
    this->cnt = cnt;
  }

  bool operator>(const Node &n) const {
    return cnt > n.cnt;
  }
};

int main() {
  int N, M;
  cin >> N >> M;

  int a, b;
  for (int i = 0; i < M; ++i) {
    cin >> a >> b;

    E[a].insert(b);
    E[b].insert(a);
  }

  priority_queue <Node, vector<Node>, greater<Node>> pque;

  for (int i = 1; i <= N; ++i) {
    pque.push(Node(i, E[i].size()));
  }

  int cnt = 0;
  vector<int> MIN_CNT(N + 1, 9999);

  while (not pque.empty()) {
    Node node = pque.top();
    pque.pop();

    if (node.cnt != 1) continue;
    if (MIN_CNT[node.v] < node.cnt) continue;
    ++cnt;

    int u = *E[node.v].begin();
    E[node.v].erase(u);
    E[u].erase(node.v);

    MIN_CNT[u] = E[u].size();
    pque.push(Node(u, E[u].size()));
  }

  if (cnt % 2 == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
0