結果

問題 No.479 頂点は要らない
ユーザー maimai
提出日時 2016-10-11 13:06:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 1,500 ms
コード長 1,653 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 172,956 KB
実行使用メモリ 9,708 KB
最終ジャッジ日時 2023-08-24 20:04:45
合計ジャッジ時間 5,545 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 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,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 50 ms
9,464 KB
testcase_27 AC 48 ms
9,440 KB
testcase_28 AC 38 ms
9,708 KB
testcase_29 AC 36 ms
6,812 KB
testcase_30 AC 35 ms
6,820 KB
testcase_31 AC 36 ms
6,804 KB
testcase_32 AC 36 ms
6,808 KB
testcase_33 AC 36 ms
7,112 KB
testcase_34 AC 39 ms
7,568 KB
testcase_35 AC 33 ms
5,976 KB
testcase_36 AC 18 ms
4,696 KB
testcase_37 AC 38 ms
7,252 KB
testcase_38 AC 33 ms
6,464 KB
testcase_39 AC 24 ms
6,012 KB
testcase_40 AC 30 ms
7,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;


int main(){
    int n,m;
    int i,j,k;
    int a,b;
    
    cin >> n>>m;
    
    vector<vector<int>> vertex(n);
    vector<pair<int,int>> edgeset(m);
    
    for (i=0;i<m;i++){
        scanf("%d%d",&a,&b);
        // 辺に頂点情報を持たせる
        edgeset[i].first=b;
        edgeset[i].second=a;
        vertex[a].emplace_back(i);
        vertex[b].emplace_back(i);
    }
    
    vector<bool> result(n,false);
    
    // 一番高価な頂点からループ
    for (int i=n-1;0<=i;i--){ // O(N+M)
        // もし頂点に隣接する辺のうち1つでも一方の頂点が削除済みであるならば
        bool need=false;
        for (int j : vertex[i]){
            if ((edgeset[j].first==-1) ^ (edgeset[j].second==-1)){
                // その頂点は必要。
                need = true;
                break;
            }
        }
        if (need){
            result[i]=true;
            // 隣接する辺そのものを除去する。
            for (int j : vertex[i]){
                edgeset[j].first=-1;
                edgeset[j].second=-1;
            }
        }else{
            // 隣接する辺の、自身の情報を消去する。
            for (int j : vertex[i]){
                if (edgeset[j].first==i)
                    edgeset[j].first=-1;
                else
                    edgeset[j].second=-1;
            }
        }
    }
    
    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