結果

問題 No.479 頂点は要らない
ユーザー masa
提出日時 2017-01-27 23:35:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 189 ms / 1,500 ms
コード長 1,032 bytes
コンパイル時間 853 ms
コンパイル使用メモリ 83,372 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-12-23 17:44:05
合計ジャッジ時間 4,367 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

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