結果

問題 No.483 マッチ並べ
ユーザー parukiparuki
提出日時 2017-02-12 20:21:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,126 bytes
コンパイル時間 2,609 ms
コンパイル使用メモリ 179,644 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 14:54:21
合計ジャッジ時間 4,750 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

class UnionFind{
    int cnt;
    vector<int> par, rank, size;
public:
    UnionFind(){}
    UnionFind(int _n):cnt(_n), par(_n), rank(_n), size(_n, 1){
        for(int i=0;i<_n;++i) par[i]=i;
    }
    int find(int k){
        return (k==par[k])?k:(par[k]=find(par[k]));
    }
    int operator[](int k){
        return find(k);
    }
    int getSize(int k){
        return size[find(k)];
    }
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x==y) return;
        --cnt;
        if(rank[x] < rank[y]){
            par[x] = y;
            size[y] += size[x];
        }else{
            par[y] = x;
            size[x] += size[y];
            if(rank[y] == rank[x]) ++rank[x];
        }
    }
    int count(){
        return cnt;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vi r0, c0, r1, c1;
    r0 = c0 = r1 = c1 = vi(N);
    vi X, Y;
    map<pii, int> p2i;
    vi u(N), v(N);
    rep(i, N) {
        cin >> r0[i] >> c0[i] >> r1[i] >> c1[i];
        pii a = mp(r0[i], c0[i]), b = mp(r1[i], c1[i]);
        for(auto p : {a,b}) {
            if(!p2i.count(p)) {
                int m = sz(p2i);
                p2i[p] = m;
            }
        }
        u[i] = p2i[a], v[i] = p2i[b];
    }
    
    const int M = sz(p2i);
    UnionFind uf(M);
    rep(i, N) uf.unite(u[i], v[i]);
    vi deg(M);
    rep(i, N) {
        deg[uf[u[i]]]++;
        deg[uf[v[i]]]++;
    }
    string ans = "YES";
    rep(i, M) {
        if(deg[uf[i]] > 2*uf.getSize(i))ans = "NO";
    }
    cout << ans << endl;
}
0