結果

問題 No.479 頂点は要らない
ユーザー maimai
提出日時 2016-10-11 13:08:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,609 bytes
コンパイル時間 1,895 ms
コンパイル使用メモリ 171,804 KB
実行使用メモリ 13,264 KB
最終ジャッジ日時 2023-08-24 20:05:00
合計ジャッジ時間 5,863 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,732 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

// 参考:O(n(n+m))

int main(){
    int n,m;
    int i,j,k;
    int a,b;
    
    cin >> n>>m;
    
    vector<vector<int>> vertex(n);
    
    for (i=0;i<m;i++){
        scanf("%d%d",&a,&b);
        // edgeset[i][1]=b;
        // edgeset[i][0]=a;
        vertex[a].emplace_back(i);
        vertex[b].emplace_back(i);
    }
    
    int result_covered = 0;
    int current_covered = 0;
    vector<bool> result(n,false);
    vector<bool> removed_edge(m,false);
    vector<bool> memo(m,false);
    
    // 全ての辺を除去するまでループ
    while (result_covered < m){// O(N)
        
        copy(removed_edge.begin(),removed_edge.end(), memo.begin());
        current_covered = result_covered;
        
        // 全ての辺を被覆するまでコストの小さい頂点から追加する
        for (i = 0;current_covered < m && i < n-1; i++){ // 計算量 O(N+M)
            for (int edge_idx : vertex[i]){
                current_covered+= !memo[edge_idx];
                memo[edge_idx] = true;
            }
        }
        // 最後に追加した頂点が必要
        i--;
        result[i] = true;
        
        // 最後に追加した頂点の周囲の辺を除去する
        for (int edge_idx : vertex[i]){
            result_covered+= !removed_edge[edge_idx];
            removed_edge[edge_idx] = true;
        }
    }
    
    bool zero=false;
    for (i=n-1; 0<=i; i--){
        if (!zero && result[i]) zero=true;
        if (zero||result[i])
            printf("%d",result[i]&1);
    }
    cout<<endl;

    return 0;
}
0