結果

問題 No.479 頂点は要らない
ユーザー koba-e964
提出日時 2017-01-27 23:33:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 75 ms / 1,500 ms
コード長 967 bytes
コンパイル時間 935 ms
コンパイル使用メモリ 64,840 KB
実行使用メモリ 10,100 KB
最終ジャッジ日時 2024-12-23 17:04:10
合計ジャッジ時間 3,184 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

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