# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
745339 | Markomafko972 | Senior Postmen (BOI14_postmen) | C++14 | 558 ms | 119152 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>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);
int n, m, a, b;
set<int> s[500005];
vector<int> v;
vector<int> ost;
int bio[500005];
vector<int> rj[500005];
int sol = 0;
void dfs(int x) {
while (s[x].size() > 0) {
int sus = *s[x].begin();
s[sus].erase(x);
s[x].erase(sus);
dfs(sus);
}
v.push_back(x);
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
s[a].insert(b);
s[b].insert(a);
}
dfs(1);
reverse(v.begin(), v.end());
int kol = 0;
for (int i = 0; i < v.size(); i++) {
if (bio[v[i]]) {
rj[sol].push_back(v[i]);
while (ost.back() != v[i]) {
rj[sol].push_back(ost.back());
bio[ost.back()]--;
ost.pop_back();
}
kol += rj[sol].size();
sol++;
}
else {
bio[v[i]] = 1;
ost.push_back(v[i]);
}
}
if (kol != m) assert(0);
for (int i = 0; i < sol; i++) {
for (int j = 0; j < rj[i].size(); j++) cout << rj[i][j] << " ";
cout << "\n";
}
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... |