Submission #1106635

#TimeUsernameProblemLanguageResultExecution timeMemory
1106635catashiro31Senior Postmen (BOI14_postmen)C++17
0 / 100
1 ms460 KiB
#include <bits/stdc++.h> #define endl '\n' #define mod 1000000007 using namespace std; void DFS(vector<pair<int,int>> adjList[], int u, vector<int> &degree, vector<bool> &edge, vector<int> &cycle) { degree[u]-=2; for (auto x : adjList[u]) { int v = x.first, pos = x.second; if (degree[v] && !edge[pos]) { edge[pos] = true; DFS(adjList,v,degree,edge,cycle); } } cycle.push_back(u); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; vector<pair<int,int>> adjList[n]; vector<int> degree(n,0); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; adjList[u-1].push_back({v-1,i}); adjList[v-1].push_back({u-1,i}); degree[u-1]++; degree[v-1]++; } vector<bool> edge(m,false); for (int i = 0; i < n; i++) { vector<int> cycle; if (degree[i]) DFS(adjList,i,degree,edge,cycle); reverse(cycle.begin(),cycle.end()); for (int vl : cycle) cout << vl+1 << " "; cout << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...