Submission #1126713

#TimeUsernameProblemLanguageResultExecution timeMemory
1126713DenisovPipes (CEOI15_pipes)C++20
70 / 100
2060 ms18636 KiB
//#pragma GCC optimize("Ofast", "unroll-loops") //#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4") #include <bits/stdc++.h> #define all(a) a.begin(),a.end() #define len(a) (int)(a.size()) #define mp make_pair #define pb push_back #define fir first #define sec second #define fi first #define se second using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef long double ld; template<typename T> bool umin(T &a, T b) { if (b < a) { a = b; return true; } return false; } template<typename T> bool umax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #ifdef KIVI #define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false) #define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); } #else #define DEBUG while (false) #define LOG(...) #endif const int max_n = 1e5 + 11, inf = 1000111222; struct dsu { public: int n; vector <int> p, cnt; inline void make_set (int v) { p[v] = v; } dsu (int n) : n(n) { p.resize(n); cnt.assign(n, 1); for (int i = 0; i < n; i++) { make_set(i); } } inline int get (int v) { if (p[v] == v) return v; return p[v] = get(p[v]); /// compressing path } inline bool unite (int a, int b) { a = get(a); b = get(b); if (a == b) return false; if (cnt[a] > cnt[b]) { swap(a, b); } p[a] = b; cnt[b] += cnt[a]; return true; } }; vector <pii> edge[max_n]; const int C = 1e5; int tin[max_n], tout[max_n], timer, n; bool bad[max_n]; inline void dfs (int v, int prv = -2) { tin[v] = tout[v] = timer++; for (auto [to, id] : edge[v]) { if (id == prv) { continue; } if (tin[to]) { umin(tout[v], tin[to]); if (id < n) { bad[id] = 1; } } else { dfs(to, id); umin(tout[v], tout[to]); if (id < n && tout[to] <= tin[v]) { bad[id] = 1; } } } } int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); int m; cin >> n >> m; dsu t(n); int num = 0; vector <pii> ee; int id = 0; for (int i = 0, u, v; i < m; ) { int r = min(i + C, m), it = 0; for (int j = 0; j < n; j++) { edge[j].clear(); } for (int j = 0; j < len(ee); j++) { edge[ee[j].first].pb({ee[j].second, j}); edge[ee[j].second].pb({ee[j].first, j}); } while (i < r) { cin >> u >> v; --u, --v; if (t.unite(u, v)) { edge[u].pb({v, id}); edge[v].pb({u, id}); ee.pb({u, v}); ++id; } else { edge[u].pb({v, n + it}); edge[v].pb({u, n + it}); ++it; } ++i; } for (int j = 0; j < n; j++) tin[j] = 0; timer = 1; for (int j = 0; j < n; j++) { if (!tin[j]) { dfs(j); } } } for (int i = 0; i < id; i++) { if (!bad[i]) { cout << ee[i].first + 1 << ' ' << ee[i].second + 1 << '\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...