結果

問題 No.483 マッチ並べ
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-04-10 01:47:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,232 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 174,376 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 10:28:27
合計ジャッジ時間 3,429 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,384 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 5 ms
4,384 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 5 ms
4,380 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 4 ms
4,380 KB
testcase_42 AC 5 ms
4,376 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 4 ms
4,376 KB
testcase_54 AC 5 ms
4,376 KB
testcase_55 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<P> vp;
typedef vector<ll> vll;

// 入力に出現する頂点が非連結でもOK
// !!!!!!!打倒 test15.txt!!!!!!!!

const int H = 100;
const int W = 100;
const int SIZE = H * W;

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int N;
    cin >> N;

    // 各頂点の次数を記録
    vi deg(SIZE, 0);
    // 各頂点の連結成分番号を記録 (頂点自身の番号で初期化)
    vi comp(SIZE);
    rep(i, SIZE) comp[i] = i;

    int num = 0;
    rep(i, N) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        r1--; c1--; r2--; c2--;

        int u = r1 * W + c1;
        int v = r2 * W + c2;

        // 次数は始点側にのみ記録しておく (こうすると総和を取ったときあとで2で割らなくて済むので)
        deg[u]++;

        // もし辺の両端の番号が異なっていれば連結させる
        if (comp[u] != comp[v]) {
            int min_c = min(comp[u], comp[v]);
            int max_c = min(comp[u], comp[v]);

            // 大きい方の番号を小さい方に置き換える
            rep(i, SIZE) {
                if (comp[i] == max_c) {
                    comp[i] = min_c;
                }
            }
        }
    }

    // 連結成分番号、(頂点数, 辺の本数)
    map<int, P> mp;
    rep(i, SIZE) {
        mp[comp[i]].first++;
        mp[comp[i]].second += deg[i];
    }

    // 各連結成分について、サイクルが 1個以下であるか確認
    for (auto p : mp) {
        int num_of_vertice = p.second.first;
        int num_of_edges = p.second.second;

        // 辺の本数 > 頂点数ならば、この連結成分は サイクルを 2個 以上含むので不適
        if (num_of_edges > num_of_vertice) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

}
0