結果
| 問題 |
No.479 頂点は要らない
|
| ユーザー |
|
| 提出日時 | 2017-04-20 03:26:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 1,500 ms |
| コード長 | 1,439 bytes |
| コンパイル時間 | 561 ms |
| コンパイル使用メモリ | 59,088 KB |
| 実行使用メモリ | 9,984 KB |
| 最終ジャッジ日時 | 2024-07-19 10:42:38 |
| 合計ジャッジ時間 | 3,080 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
#include <cstdio>
#include <vector>
#include <algorithm>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
int main() {
// input
int n, m; scanf("%d%d", &n, &m);
vector<int> a(m), b(m); repeat (i,m) scanf("%d%d", &a[i], &b[i]);
// prepare list
vector<vector<int> > g(n);
repeat (i,m) {
g[a[i]].push_back(i);
g[b[i]].push_back(i);
}
// solve
// // greedy
vector<bool> result(n);
vector<int> used(m);
int count_used = 0;
repeat (j,n) {
result[j] = true;
for (int i : g[j]) {
if (used[i] == 0) count_used += 1;
used[i] += 1;
}
if (count_used == m) break;
}
// // remove unnecessary vertices
repeat_reverse (j,n) if (result[j]) {
bool is_removable = true;
for (int i : g[j]) {
if (used[i] == 1) is_removable = false;
}
if (is_removable) {
result[j] = false;
for (int i : g[j]) {
used[i] -= 1;
}
}
}
// output
while (result.size() >= 2 and result.back() == false) result.pop_back();
whole(reverse, result);
for (bool p : result) printf("%d", p);
printf("\n");
return 0;
}