結果

問題 No.479 頂点は要らない
ユーザー koba-e964koba-e964
提出日時 2017-01-27 23:33:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 86 ms / 1,500 ms
コード長 967 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 65,404 KB
実行使用メモリ 10,224 KB
最終ジャッジ日時 2023-08-25 10:36:55
合計ジャッジ時間 3,653 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,692 KB
testcase_01 AC 3 ms
5,824 KB
testcase_02 AC 4 ms
5,692 KB
testcase_03 AC 3 ms
6,012 KB
testcase_04 AC 3 ms
5,688 KB
testcase_05 AC 3 ms
5,684 KB
testcase_06 AC 3 ms
5,804 KB
testcase_07 AC 3 ms
5,748 KB
testcase_08 AC 3 ms
5,696 KB
testcase_09 AC 4 ms
5,696 KB
testcase_10 AC 4 ms
5,680 KB
testcase_11 AC 3 ms
6,016 KB
testcase_12 AC 3 ms
5,884 KB
testcase_13 AC 3 ms
5,900 KB
testcase_14 AC 3 ms
6,016 KB
testcase_15 AC 4 ms
5,804 KB
testcase_16 AC 4 ms
5,752 KB
testcase_17 AC 3 ms
5,888 KB
testcase_18 AC 3 ms
5,824 KB
testcase_19 AC 3 ms
5,728 KB
testcase_20 AC 3 ms
5,752 KB
testcase_21 AC 3 ms
5,716 KB
testcase_22 AC 4 ms
5,752 KB
testcase_23 AC 4 ms
5,800 KB
testcase_24 AC 4 ms
5,748 KB
testcase_25 AC 3 ms
5,732 KB
testcase_26 AC 85 ms
9,584 KB
testcase_27 AC 86 ms
9,580 KB
testcase_28 AC 69 ms
10,224 KB
testcase_29 AC 69 ms
8,288 KB
testcase_30 AC 69 ms
8,228 KB
testcase_31 AC 69 ms
8,336 KB
testcase_32 AC 69 ms
8,208 KB
testcase_33 AC 67 ms
8,352 KB
testcase_34 AC 73 ms
8,292 KB
testcase_35 AC 64 ms
7,772 KB
testcase_36 AC 37 ms
6,776 KB
testcase_37 AC 70 ms
8,508 KB
testcase_38 AC 60 ms
7,952 KB
testcase_39 AC 43 ms
7,336 KB
testcase_40 AC 53 ms
7,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PI;

const int N = 100100;
VI link[N];

int main(void){
  int n, m;
  cin >> n >> m;
  vector<PI> e;
  REP(i, 0, m) {
    int a, b;
    cin >> a >> b;
    e.push_back(PI(a, b));
    link[a].push_back(e.size() - 1);
    link[b].push_back(e.size() - 1);
  }
  VI ans(n);
  for (int i = n - 1; i >= 0; --i) {
    // check if Vertex i is necessary or not
    bool usei = false;
    for (auto ei: link[i]) {
      if (e[ei].first == i) {
	// cannot avoid using i
        usei = true;
      }
    }
    if (not usei) {
      ans[i] = 0;
      continue;
    }
    ans[i] = 1;
    // eliminate all connecting edges
    for (auto ei: link[i]) {
      e[ei].first = -1;
    }
  }
  int ma = 0;
  REP(i, 0, n) {
    if (ans[i]) ma = i;
  }
  for (int i = ma; i >= 0; --i) {
    cout << ans[i];
  }
  cout << endl;
}
0