Submission #967695

#TimeUsernameProblemLanguageResultExecution timeMemory
967695c2zi6Senior Postmen (BOI14_postmen)C++14
100 / 100
465 ms67156 KiB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int n, m;
VVPI gp;
VI vis;
VI onstack;
stack<int> order;

void dfs(int u = 0) {
	while (gp[u].size()) {
		auto[v, ind] = gp[u].back();
		gp[u].pop_back();
		if (vis[ind]) continue;
		vis[ind] = true;
		dfs(v);
	}
	if (onstack[u]) {
		cout << u+1 << " ";
		while (order.top() != u) {
			cout << order.top()+1 << " ";
			onstack[order.top()] = false;
			order.pop();
		}
		cout << endl;
	} else {
		/* cout << u+1 << " "; */
		onstack[u] = true;
		order.push(u);
	}
}

void solve() {
	cin >> n >> m;
	gp = VVPI(n);
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		gp[u].pb({v, i});
		gp[v].pb({u, i});
	}
	vis = VI(m);
	onstack = VI(n);
	dfs();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--) solve();
}

Compilation message (stderr)

postmen.cpp: In function 'void dfs(int)':
postmen.cpp:41:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |   auto[v, ind] = gp[u].back();
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...