結果

問題 No.583 鉄道同好会
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2018-06-23 18:29:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 1,115 ms
コンパイル使用メモリ 100,192 KB
実行使用メモリ 4,548 KB
最終ジャッジ日時 2023-09-13 08:32:54
合計ジャッジ時間 2,024 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 13 ms
4,376 KB
testcase_12 AC 18 ms
4,384 KB
testcase_13 AC 18 ms
4,380 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 23 ms
4,376 KB
testcase_16 AC 41 ms
4,504 KB
testcase_17 AC 49 ms
4,508 KB
testcase_18 AC 50 ms
4,548 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:59:9: 警告: ‘s’ may be used uninitialized [-Wmaybe-uninitialized]
   59 |     func(s);
      |     ~~~~^~~
main.cpp:43:9: 備考: ‘s’ はここで定義されています
   43 |     int s;
      |         ^

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

vector< vector<int> > P;
vector<int> A;
vector<int> B;

void func( int a ) {
    B[a] = 1;

    for ( int i = 0; i < P[a].size(); i++ ) {
        int n = P[a][i];
        if ( B[n] == 0 ) {
            func(n);
        }
    }
}

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

    P.resize(N);
    A.resize(N,0);
    B.resize(N,0);

    int s;

    for ( int i = 0; i < M; i++ ) {
        int a,b;
        cin >> a >> b;        
        P[a].push_back(b);
        P[b].push_back(a);

        A[a] = 1;
        A[b] = 1;

        s = a;
    }

    bool ans = true;

    func(s);

    for ( int i = 0; i < N; i++ ) {
        if ( A[i] != B[i] ) { ans = false; }
    }

    int a = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( A[i] && P[i].size()%2 ) {
            a++;
        }
    }
    if ( !( a == 0 || a == 2 ) ) { ans = false; }

    cout << ( ans ? "YES" : "NO" ) << endl;

    return 0;
}
0