結果

問題 No.479 頂点は要らない
ユーザー maimai
提出日時 2017-01-26 00:01:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 1,500 ms
コード長 1,409 bytes
コンパイル時間 1,817 ms
コンパイル使用メモリ 171,408 KB
実行使用メモリ 9,064 KB
最終ジャッジ日時 2023-08-24 23:13:16
合計ジャッジ時間 5,191 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 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,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 46 ms
8,688 KB
testcase_27 AC 47 ms
8,652 KB
testcase_28 AC 36 ms
9,064 KB
testcase_29 AC 35 ms
5,960 KB
testcase_30 AC 35 ms
6,092 KB
testcase_31 AC 34 ms
5,960 KB
testcase_32 AC 34 ms
6,524 KB
testcase_33 AC 34 ms
6,720 KB
testcase_34 AC 37 ms
6,600 KB
testcase_35 AC 32 ms
5,264 KB
testcase_36 AC 17 ms
4,580 KB
testcase_37 AC 37 ms
6,732 KB
testcase_38 AC 31 ms
6,024 KB
testcase_39 AC 24 ms
5,596 KB
testcase_40 AC 28 ms
6,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0