Submission #199445

#TimeUsernameProblemLanguageResultExecution timeMemory
199445TadijaSebez어르신 집배원 (BOI14_postmen)C++11
55 / 100
574 ms64460 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=500050;
int was[N],wse[N];
vector<pair<int,int>> E[N];
vector<int> tmp;
vector<vector<int>> ans;
int DFS(int u){
	was[u]=1;
	while(E[u].size()){
		auto e=E[u].back();
		if(wse[e.second])E[u].pop_back();
		else{
			int v=e.first;
			wse[e.second]=1;
			if(was[v]){
				tmp.clear();
				tmp.pb(u);
				was[u]=0;
				return v;
			}else{
				int t=DFS(v);
				if(t!=u){
					tmp.pb(u);
					was[u]=0;
					return t;
				}
				tmp.pb(u);
				ans.pb(tmp);
			}
		}
	}
	return -1;
}
int main(){
	int n,m;
	scanf("%i %i",&n,&m);
	for(int i=1,u,v;i<=m;i++)scanf("%i %i",&u,&v),E[u].pb({v,i}),E[v].pb({u,i});
	for(int i=1;i<=n;i++)DFS(i);
	for(auto cyc:ans){
		for(int u:cyc)printf("%i ",u);
		printf("\n");
	}
	return 0;
}

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
postmen.cpp:39:62: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1,u,v;i<=m;i++)scanf("%i %i",&u,&v),E[u].pb({v,i}),E[v].pb({u,i});
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...