Submission #364625

#TimeUsernameProblemLanguageResultExecution timeMemory
364625LucaDantasSenior Postmen (BOI14_postmen)C++17
55 / 100
523 ms34780 KiB
#include<cstdio>
#include<vector>
#include <cassert>
#include<utility>
using namespace std;

#define pb push_back
#define sz(a) (int)(a.size())

constexpr int maxn = 5e5+10;

vector<pair<int,int>> g[maxn];
vector<int> st;

bool mark[maxn], mark_edge[maxn];

void dfs(int i) {
	st.pb(i);
	while(1) {
		int u = st.back();
		mark[u] = 1;

		while(g[u].size() && mark_edge[g[u].back().second])
			g[u].pop_back();

		if(!sz(g[u])) break;

		int v = g[u].back().first;
		mark_edge[g[u].back().second] = 1;
		g[u].pop_back();

		if(mark[v]) {
			printf("%d", v);
			while(st.size() && st.back() != v) {
				printf(" %d", st.back());
				mark[st.back()] = 0;
				st.pop_back();
			}
			printf("\n");
		}
		else st.pb(v);
	}
	mark[i] = 0;
	st.pop_back();
	assert(!sz(st));
}

int main() {
	int n, m; scanf("%d %d", &n, &m);
	for(int i = 0, a, b; i < m; i++)
		scanf("%d %d", &a, &b), g[a].pb({b, i}), g[b].pb({a, i});
	for(int i = 1; i <= n; i++)
		if(sz(g[i])) dfs(i);
}

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:49:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |  int n, m; scanf("%d %d", &n, &m);
      |            ~~~~~^~~~~~~~~~~~~~~~~
postmen.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |   scanf("%d %d", &a, &b), g[a].pb({b, i}), g[b].pb({a, i});
      |   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...