# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
31488 | aome | Senior Postmen (BOI14_postmen) | C++14 | 6 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*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];
vector<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];
vector<int> tmp;
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]) {
tmp.push_back(u);
while (!path.empty() && path.back() != u) {
if (!tmp.empty() && tmp.back() != path.back())
tmp.push_back(path.back());
in[path.back()] = false;
path.pop_back();
}
cout << tmp << endl;
tmp.clear();
}
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);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |