Submission #31494

#TimeUsernameProblemLanguageResultExecution timeMemory
31494aomeSenior Postmen (BOI14_postmen)C++14
0 / 100
6 ms512 KiB
/*input
10 15
1 3
5 1
2 3
9 2
3 4
6 3
4 5
7 4
4 8
5 7
8 5
6 7
7 8
8 10
10 9
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 205
struct data {
	int u;
	list<data>::iterator it;
	data(int _u): u(_u) {};
};

int n, m;
list<data> a[N];
deque<int> path;

void add_edge(int u, int v) {
	a[u].push_front(data(v));
	a[v].push_front(data(u));
	a[u].begin()->it = a[v].begin();
	a[v].begin()->it = a[u].begin();
}

ostream& operator << (ostream &os, vector<int>&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << sp;
	return os;
}
ostream& operator << (ostream &os, pair<int, int> x) {
	cout << x.fi << sp << x.se << sp;
	return os;
}
ostream& operator << (ostream &os, vector<pair<int, int> >&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << endl;
	return os;
}

bool in[N];
void find_path(int u) {
	while (a[u].size() > 0) {
		int v = a[u].front().u;
		list<data>::iterator it = a[u].front().it;
		a[v].erase(it);
		a[u].pop_front();
		find_path(v);
	}
	if (in[u]) {
		while (!path.empty() && path.back() != u) {
			cout << path.back() << sp; in[path.back()] = false;
			path.pop_back();
		}
		cout << path.back() << sp; in[path.back()] = false; path.pop_back();
		cout << endl;
	}
	path.push_back(u); in[u] = true;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		add_edge(u, v);
	}
	find_path(1);
	// for (int i = 0; i < path.size(); i++) cout << path[i] << sp;
	// cout << endl;
}

Compilation message (stderr)

postmen.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<long long int>&)':
postmen.cpp:66:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << sp;
                  ~~^~~~~~~~~~
postmen.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<std::pair<long long int, long long int> >&)':
postmen.cpp:74:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << endl;
                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...