# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1087040 | shidou26 | Senior Postmen (BOI14_postmen) | C++14 | 300 ms | 95680 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.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int N = 1e6 + 3;
int n, m;
int eu[N], ev[N];
vector<int> adj[N];
bool vst[N], used[N];
vector<int> nodes;
void prepare() {
}
void input() {
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int u, v; cin >> u >> v;
eu[i] = u;
ev[i] = v;
adj[u].push_back(i);
adj[v].push_back(i);
}
}
void dfs(int u) {
if(vst[u]) {
while(!nodes.empty()) {
int node = nodes.back();
cout << node << " ";
if(node == u) break;
vst[node] = false;
nodes.pop_back();
}
cout << endl;
}else {
nodes.push_back(u);
vst[u] = true;
}
while(!adj[u].empty()) {
int id = adj[u].back(); adj[u].pop_back();
if(!used[id]) {
used[id] = true;
int v = eu[id] + ev[id] - u;
dfs(v);
break;
}
}
}
void process() {
for(int i = 1; i <= n; i++) {
if(!adj[i].empty()) dfs(i);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#define task "kurumi"
if(fopen(task".INP", "r")) {
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
prepare();
int testcase = 1; // cin >> testcase;
for(int i = 1; i <= testcase; i++) {
input();
process();
}
return 0;
}
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... |