Input | Output |
5 6 1 2 2 3 3 1 2 4 4 5 2 5 |
1 2 4 5 2 3 1 |
Input | Output |
6 6 1 2 2 3 2 5 2 6 5 6 4 3 |
1 2 5 6 2 3 4 |
#include<bits/stdc++.h> #include<iostream> using namespace std; using ll = long long; const int maxN = 100001; const int INF = 1e9; // so vo cung int n, m; // n: so dinh, m: so canh set<int> adj[maxN]; // tap hop luu dinh ke int degree[maxN]; // bac cua dinh void inp() { cin >> n >> m; for(int i=0; i<m; i++) { int x, y; cin >> x >> y; adj[x].insert(y); adj[y].insert(x); degree[x]++; degree[y]++; } } void euler(int v) { stack<int> st; vector<int> EC; // Chu trinh Euler st.push(v); while(!st.empty()) { int x = st.top(); if(adj[x].size() != 0) { int y = *adj[x].begin(); st.push(y); //xoa(x,y) adj[x].erase(y); adj[y].erase(x); } else { st.pop(); EC.push_back(x); } } reverse(begin(EC), end(EC)); for(int x: EC) { cout << x << ' '; } } int main() { // Chuyen NHAP, XUAT thanh file freopen("lab_7_input.INP", "r", stdin); freopen("lab_7_output.OUT", "w", stdout); // INPUT inp(); // OUTPUT euler(1); }
Cùng nhau học tập, khám phá các kiến thức nền tảng về Lập trình web, mobile, database nhé.
Nền tảng kiến thức - Hành trang tới tương lai hân hạnh phục vụ Quý khách!
Khám phá, trải nghiệm ngay
Vui lòng đăng nhập để gởi bình luận!
Đăng nhậpChưa có bình luận nào!