Submission #31519

#TimeUsernameProblemLanguageResultExecution timeMemory
31519aomeSenior Postmen (BOI14_postmen)C++11
55 / 100
602 ms98700 KiB
/*input
5 10
1 5
1 3
2 4
2 5
2 3
1 2
3 4
4 5
3 5
1 4

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 500005
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];
		if (i != x.size() - 1) os << 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];
vector<vector<int> > ans;
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);
	}
	vector<int> tmp;
	if (in[u]) {
		while (!path.empty() && path.back() != u) {
			tmp.push_back(path.back());
			in[path.back()] = false;
			path.pop_back();
		}
		tmp.push_back(path.back());
		in[path.back()] = false; path.pop_back();
		ans.push_back(tmp);
	}
	path.push_back(u); in[u] = true;
}

signed main() {
// #ifdef UncleGrandpa
// 	freopen("input.txt", "r", stdin);
// #endif
	ios_base::sync_with_stdio(false);
	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 < ans.size(); i++) {
		cout << ans[i];
		if (i != ans.size() - 1) cout << endl;
	}
	// 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:78:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) {
                  ~~^~~~~~~~~~
postmen.cpp:80:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (i != x.size() - 1) os << sp;
       ~~^~~~~~~~~~~~~~~
postmen.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<std::pair<long long int, long long int> >&)':
postmen.cpp:89:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << endl;
                  ~~^~~~~~~~~~
postmen.cpp: In function 'int main()':
postmen.cpp:129:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ans.size(); i++) {
                  ~~^~~~~~~~~~~~
postmen.cpp:131:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (i != ans.size() - 1) cout << endl;
       ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...