結果

問題 No.479 頂点は要らない
ユーザー cormorancormoran
提出日時 2017-04-18 18:51:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 1,500 ms
コード長 1,395 bytes
コンパイル時間 2,105 ms
コンパイル使用メモリ 173,328 KB
実行使用メモリ 9,352 KB
最終ジャッジ日時 2023-09-26 13:24:41
合計ジャッジ時間 4,315 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 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,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 50 ms
9,184 KB
testcase_27 AC 50 ms
9,172 KB
testcase_28 AC 30 ms
9,352 KB
testcase_29 AC 32 ms
6,660 KB
testcase_30 AC 31 ms
6,756 KB
testcase_31 AC 32 ms
6,712 KB
testcase_32 AC 33 ms
6,704 KB
testcase_33 AC 40 ms
7,140 KB
testcase_34 AC 44 ms
7,164 KB
testcase_35 AC 32 ms
5,976 KB
testcase_36 AC 16 ms
4,432 KB
testcase_37 AC 42 ms
7,244 KB
testcase_38 AC 33 ms
6,440 KB
testcase_39 AC 25 ms
5,952 KB
testcase_40 AC 31 ms
7,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define rrep(i, j) for(int i=(j)-1; i >= 0; i--)
#define all(v) v.begin(),v.end()

class Solver {
  public:
    bool solve() {
        int N, M; cin >> N >> M;        
        vector<vector<int>> E(N);
        rep(i, M) {
            int a, b; cin >> a >> b;
            E[a].push_back(i);
            E[b].push_back(i);
        }
        
        vector<bool> need_to_buy(N);
        vector<int> used_by(M, -1);
        rep(n, N) {
            bool flg = false;
            for(int e : E[n]) {
                if(used_by[e] < 0) {
                    flg = true;
                    used_by[e] = n;
                }
            }
            need_to_buy[n] = flg;
        }

        string ans = "";
        rrep(n, N) {
            if(need_to_buy[n]) {            
                bool flg = false;
                for(int e : E[n]) flg |= used_by[e] == n;
                if(flg) {
                    for(int e : E[n]) used_by[e] = n;
                }
                ans.push_back(flg ? '1' : '0'); 
            } else {
                ans.push_back('0');
            }
            if(ans == "0") ans = "";
        }

        cout << ans << endl;
        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0