結果
| 問題 |
No.483 マッチ並べ
|
| コンテスト | |
| ユーザー |
🍡yurahuna
|
| 提出日時 | 2016-04-10 03:21:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 2,215 bytes |
| コンパイル時間 | 1,800 ms |
| コンパイル使用メモリ | 177,188 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-29 07:56:49 |
| 合計ジャッジ時間 | 3,397 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 53 |
ソースコード
#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;
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 = max(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;
}
🍡yurahuna