結果
問題 | No.479 頂点は要らない |
ユーザー | koba-e964 |
提出日時 | 2017-01-27 23:27:14 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 94 ms / 1,500 ms |
コード長 | 1,444 bytes |
コンパイル時間 | 864 ms |
コンパイル使用メモリ | 95,344 KB |
実行使用メモリ | 10,104 KB |
最終ジャッジ日時 | 2024-12-23 17:01:01 |
合計ジャッジ時間 | 3,543 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; typedef vector<int> VI; typedef vector<ll> VL; typedef pair<int, int> PI; const ll mod = 1e9 + 7; const int N = 100100; VI link[N]; int main(void){ int n, m; cin >> n >> m; vector<PI> e; REP(i, 0, m) { int a, b; cin >> a >> b; e.push_back(PI(a, b)); link[a].push_back(e.size() - 1); link[b].push_back(e.size() - 1); } VI ans(n); for (int i = n - 1; i >= 0; --i) { // check if Vertex i is necessary or not bool usei = false; for (auto ei: link[i]) { if (e[ei].first == i) { // cannot avoid using i usei = true; } } if (not usei) { ans[i] = 0; continue; } ans[i] = 1; // eliminate all connecting edges for (auto ei: link[i]) { e[ei].first = -1; e[ei].second = -1; } } int ma = 0; REP(i, 0, n) { if (ans[i]) ma = i; } for (int i = ma; i >= 0; --i) { cout << ans[i]; } cout << endl; }