結果

問題 No.483 マッチ並べ
ユーザー 🍡yurahuna
提出日時 2016-04-10 20:47:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,655 bytes
コンパイル時間 1,958 ms
コンパイル使用メモリ 169,936 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 07:57:09
合計ジャッジ時間 3,287 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41 WA * 12
権限があれば一括ダウンロードができます

ソースコード

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;

/******** U.S.O. 1 ***********/
// 方針:「グラフが閉路を1つでも含んでいたらダメ」

// 対策:「閉路がちょうど1個」の連結成分があるケースで落ちる
/*****************************/

const int H = 100;
const int W = 100;
const int SIZE = H * W;
vector<vector<int>> G(SIZE);
bool done[SIZE];
int N;
bool contains_cycle;

void dfs(int now, int pre) {
    done[now] = true;

    for (int nxt : G[now]) {
        if (nxt == pre) continue;
        if (done[nxt]) {
            contains_cycle = true;
            continue;
        }

        dfs(nxt, now);
    }

}

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

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

        int node1 = r1 * W + c1;
        int node2 = r2 * W + c2;
        G[node1].emplace_back(node2);
        G[node2].emplace_back(node1);
    }

    // 各頂点からDFSし、頂点をつぶしていく
    // もし閉路があれば、フラグ(contains_cycle)に記録しておく
    rep(i, SIZE) {
        if (!done[i]) dfs(i, -1);
    }

    if (contains_cycle) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

}
0