이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#define _GLIBCXX_DEBUG
//#define _GLIBCXX_DEBUG_PEDANTIC
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
int main() {
// std::ios_base::sync_with_stdio(false);
// std::cin.tie(nullptr);
int nvertex, nedge;
std::cin >> nvertex >> nedge;
std::vector<std::set<int>> adjlist (nvertex);
for (int i = 0; i < nedge; ++i) {
int u, v;
std::cin >> u >> v;
adjlist[--u].insert(--v);
adjlist[v].insert(u);
}
// std::cout << "------------\n";
std::vector<int> passedvertices;
std::vector<char> passedp (nvertex, false);
for (int vertex = 0; vertex < nvertex; ++vertex) {
// std::cout << "vertex = " << vertex << '\n';
while (!adjlist[vertex].empty()) {
passedvertices.push_back(vertex);
passedp[vertex] = true;
while ((!passedvertices.empty()) && !adjlist[passedvertices.back()].empty()) {
int nextvertex = *adjlist[passedvertices.back()].begin();
// std::cout << "nextvertex = " << nextvertex << '\n';
adjlist[passedvertices.back()].erase(adjlist[passedvertices.back()].begin());
adjlist[nextvertex].erase(passedvertices.back());
if (passedp[nextvertex]) {
// std::cout << "Cycle :\n";
do {
std::cout << 1+passedvertices.back() << ' ';
passedp[passedvertices.back()] = false; passedvertices.pop_back();
} while (passedvertices.back() != nextvertex);
std::cout << 1+nextvertex << '\n';
} else {
passedvertices.push_back(nextvertex);
passedp[nextvertex] = true;
}
}
// if ((!passedvertices.empty()) && adjlist[passedvertices.back()].empty()) {
// std::cout << "error\n";
// for (int i : passedvertices) std::cout << i << ' ';
// std::cout << '\n';
// while (true);
// }
// else std::cout << "****\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |