結果
問題 |
No.479 頂点は要らない
|
ユーザー |
![]() |
提出日時 | 2017-04-18 18:51:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 37 ms / 1,500 ms |
コード長 | 1,395 bytes |
コンパイル時間 | 1,416 ms |
コンパイル使用メモリ | 174,184 KB |
実行使用メモリ | 9,744 KB |
最終ジャッジ日時 | 2024-07-19 07:46:15 |
合計ジャッジ時間 | 2,995 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#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; }