제출 #1278184

#제출 시각아이디문제언어결과실행 시간메모리
1278184mdobric어르신 집배원 (BOI14_postmen)C++20
55 / 100
598 ms266140 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 500005; int n, m, a[maxn], b[maxn]; vector <int> v[maxn], tura; int br[maxn], bio1[maxn]; unordered_map <int, int> bio2[maxn]; set <int> s[maxn]; set <int> ::iterator it; vector <int> ans[maxn]; int maxi = 0; void eulers_tour (int x){ while (br[x] < v[x].size()){ int y = v[x][br[x]]; br[x]++; if (bio1[y] == 0 and bio2[x][y] == 0){ bio2[x][y] = 1; bio2[y][x] = 1; eulers_tour(y); } } bio1[x] = 1; tura.push_back(x); } void solve (int poc, int kraj, int brojac){ maxi = max(maxi, brojac); for (int i = poc; i <= kraj; i++){ ans[brojac].push_back(tura[i]); it = s[tura[i]].lower_bound(kraj + 1); it--; if (*it > i and *it <= kraj){ solve(i + 1, *it, maxi + 1); it = s[tura[i]].lower_bound(kraj + 1); it--; i = *it; } } } int main (void){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for (int i = 0; i < m; i++){ cin >> a[i] >> b[i]; v[a[i]].push_back(b[i]); v[b[i]].push_back(a[i]); } eulers_tour(1); for (int i = 0; i < tura.size() - 1; i++) s[tura[i]].insert(i); solve(0, tura.size() - 2, 0); for (int i = 0; i <= maxi; i++){ for (int j = 0; j < ans[i].size(); j++) cout << ans[i][j] << " "; cout << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...