結果

問題 No.479 頂点は要らない
ユーザー fura
提出日時 2020-06-21 01:56:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 1,500 ms
コード長 615 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 197,424 KB
最終ジャッジ日時 2025-01-11 08:51:02
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         int n,m; scanf("%d%d",&n,&m);
      |                  ~~~~~^~~~~~~~~~~~~~
main.cpp:18:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |                 int u,v; scanf("%d%d",&u,&v);
      |                          ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using graph=vector<vector<int>>;

void add_undirected_edge(graph& G,int u,int v){
	G[u].emplace_back(v);
	G[v].emplace_back(u);
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	graph G(n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v);
		add_undirected_edge(G,u,v);
	}

	string ans(n,'?');
	for(int u=n-1;u>=0;u--){
		bool need=false;
		for(int v:G[u]) if(ans[v]=='0') need=true;
		ans[u]=(need?'1':'0');
	}
	while(ans.length()>=2 && ans.back()=='0') ans.pop_back();
	reverse(ans.begin(),ans.end());
	cout<<ans<<'\n';

	return 0;
}
0