結果

問題 No.583 鉄道同好会
ユーザー pekempeypekempey
提出日時 2017-10-27 22:40:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 70,688 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 17:14:06
合計ジャッジ時間 2,810 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 176 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 176 ms
6,944 KB
testcase_11 AC 115 ms
6,944 KB
testcase_12 AC 118 ms
6,944 KB
testcase_13 AC 120 ms
6,940 KB
testcase_14 AC 119 ms
6,940 KB
testcase_15 AC 124 ms
6,940 KB
testcase_16 AC 144 ms
6,940 KB
testcase_17 AC 153 ms
6,944 KB
testcase_18 AC 152 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

bool g[500][500];

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> deg(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    deg[u]++;
    deg[v]++;
    g[u][v] = true;
    g[v][u] = true;
  }
  for (int i = 0; i < n; i++) g[i][i] = true;
  for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) g[i][j] |= g[i][k] && g[k][j];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (deg[i] > 0 && deg[j] > 0 && !g[i][j]) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }

  int odd = 0;
  int even = 0;
  for (int i = 0; i < n; i++) {
    even += deg[i] % 2 == 0;
    odd += deg[i] % 2 == 1;
  }
  
  if (odd == 0 || odd == 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
0