結果
問題 |
No.479 頂点は要らない
|
ユーザー |
|
提出日時 | 2017-01-26 00:01:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 42 ms / 1,500 ms |
コード長 | 1,409 bytes |
コンパイル時間 | 1,471 ms |
コンパイル使用メモリ | 174,408 KB |
実行使用メモリ | 9,216 KB |
最終ジャッジ日時 | 2024-12-23 09:45:43 |
合計ジャッジ時間 | 4,037 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include<bits/stdc++.h> using namespace std; class UndirectedGraph{ public: size_t n; vector<vector<int>> vertex_to; UndirectedGraph(size_t n):n(n),vertex_to(n){} void connect(int from, int to){ vertex_to[from].emplace_back(to); vertex_to[to].emplace_back(from); } vector<int>& operator[](int v){ return vertex_to[v]; } void resize(size_t _n){ n = _n; vertex_to.resize(_n); } size_t degree(int v){ return vertex_to[v].size(); } }; int m,n; int main(){ int i,j,k; int x,y,a,b; cin >> n>>m; UndirectedGraph graph(n); vector<bool> deleted(n,false); for (i=0; i<m; ++i){ scanf("%d%d",&a,&b); graph.connect(a,b); } // 一番高価な頂点からループ for (i=n-1; 0<=i; --i){ // もし頂点に接続する辺のうち1つでも一方の頂点が選択されないかつ探索済みであるならば // その頂点は選択されるべき for (int to : graph.vertex_to[i]){ if (i<to && !deleted[to]){ deleted[i] = true; break; } } } bool zero=false; for (i=n-1; 0<=i; i--){ if (!zero && deleted[i]) zero=true; if (zero||deleted[i]) printf("%d",deleted[i]&1); } cout<<endl; return 0; }