# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1050273 | christinelynn | Senior Postmen (BOI14_postmen) | C++17 | 58 ms | 13120 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 int long long
int n, m;
vector<pair<int, int>> adj[100005];
int ind[100005];
bool ya[100005], vis[100005];
vector<pair<int, int>> star;
void dfs(int a) {
stack<int> s;
s.push(a);
vis[a] = true;
while(true) {
int b = s.top();
while(true) {
if(ind[b] == adj[b].size()) {
break;
}
int c = adj[b][ind[b]].second;
if(ya[c] == true) {
ind[b]++;
} else {
break;
}
}
if(ind[b] == adj[b].size()) {
//cout << b << "\n";
if(s.size() > 1) {
while(!s.empty()) {
cout << s.top() << " ";
vis[s.top()] = false;
s.pop();
}
cout << "\n";
} else {
vis[b] = false;
}
break;
}
int nxt = adj[b][ind[b]].first, jo = adj[b][ind[b]].second;
ind[b]++;
ya[jo] = true;
if(vis[nxt] == true) {
cout << nxt << " ";
while(s.top() != nxt) {
cout << s.top() << " ";
vis[s.top()] = false;
s.pop();
}
cout << "\n";
} else {
vis[nxt] = true;
s.push(nxt);
}
}
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++) {
int y, z;
cin >> y >> z;
star.push_back({y, z});
adj[y].push_back({z, i});
adj[z].push_back({y, i});
}
for(int i = 0; i < m; i++) {
if(ya[i] == false) {
ya[i] = true;
//cout << i << "\n";
dfs(star[i].first);
}
}
}
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... |