結果

問題 No.479 頂点は要らない
ユーザー masamasa
提出日時 2017-01-27 23:35:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 161 ms / 1,500 ms
コード長 1,032 bytes
コンパイル時間 1,006 ms
コンパイル使用メモリ 82,808 KB
実行使用メモリ 17,608 KB
最終ジャッジ日時 2023-08-25 11:03:56
合計ジャッジ時間 4,485 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 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,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 131 ms
17,476 KB
testcase_27 AC 129 ms
17,484 KB
testcase_28 AC 116 ms
17,608 KB
testcase_29 AC 93 ms
14,816 KB
testcase_30 AC 93 ms
14,872 KB
testcase_31 AC 93 ms
14,920 KB
testcase_32 AC 92 ms
14,988 KB
testcase_33 AC 128 ms
13,540 KB
testcase_34 AC 149 ms
14,464 KB
testcase_35 AC 161 ms
13,192 KB
testcase_36 AC 90 ms
9,324 KB
testcase_37 AC 141 ms
14,340 KB
testcase_38 AC 114 ms
12,660 KB
testcase_39 AC 68 ms
10,116 KB
testcase_40 AC 84 ms
12,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>

using namespace std;

template <class T>
void show(T t) {
	for (auto e : t) {
		printf("%3d ", e);
	}
	cout << endl;
}

int main() {
	int n, m, a, b;
	cin >> n >> m;

	vector<set<int>> edge(n, set<int>());
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		edge[a].insert(b);
		edge[b].insert(a);
	}
	vector<int> buy(n, -1);

	for (int i = n - 1; i >= 0; i--) {
// printf("i %d, buy %d\n", i, buy[i]);
		if (buy[i] <= 0) {
			buy[i] = 0;
			for (auto val : edge[i]) {
				buy[val] = 1;
			}
		} else if (buy[i] == 1) {
			for (auto it = edge[i].begin(); it != edge[i].end();) {
				edge[*it].erase(i);
				if (edge[i].count(*it)) {
					it = edge[i].erase(it);
				} else {
					it++;
				}
			}
		}
	}

	bool leading_zero = true;
	for (int i = n - 1; i >= 0; i--) {
		if (leading_zero) {
			if (buy[i] == 0) {
				continue;
			} else {
				leading_zero = false;
			}
		}
		cout << buy[i];
	}
	cout << endl;
	return 0;
}
0