結果

問題 No.483 マッチ並べ
ユーザー kosakkunkosakkun
提出日時 2017-04-11 18:08:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,240 bytes
コンパイル時間 1,151 ms
コンパイル使用メモリ 111,860 KB
実行使用メモリ 4,668 KB
最終ジャッジ日時 2023-09-25 11:13:07
合計ジャッジ時間 4,354 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <fstream>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

class UnionFind {
    vector<int> data;
public:
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

int ver(int r, int c){
    return r*200 + c+1;
}

int main(){

    int N;
    cin >> N;

    UnionFind inst(20000);
    vector< pair<int,int> > edge;
    REP(i,N){
        int r0,c0,r1,c1;
        cin >> r0 >> c0 >> r1 >> c1;
        int v1 = ver(r0,c0);
        int v2 = ver(r1,c1);
        edge.push_back(make_pair(v1,v2));
        inst.unionSet(v1,v2);
    }
    
    set<int> vcnt[20000];
    set<int> group;
    map<int,int> ecnt;
    REP(i,edge.size()){
        int r = inst.root(edge[i].first);
        vcnt[r].insert(edge[i].first);
        vcnt[r].insert(edge[i].second);
        ecnt[r]++;
        group.insert(r);
    }
    
    for(auto v : group){
        int ec = ecnt[v];
        int vc = (int)vcnt[v].size();
        if(ec > vc){
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    
    return 0;
}
0