제출 #1062109

#제출 시각아이디문제언어결과실행 시간메모리
1062109trMatherzPipes (CEOI15_pipes)C++17
20 / 100
1024 ms65536 KiB
#include <iostream> // #include <fstream> // std::ifstream cin ("pop.in"); // std::ofstream cout ("pop.out"); // includes #include <cmath> #include <set> #include <map> #include <queue> #include <string> #include <vector> #include <array> #include <algorithm> #include <numeric> #include <iomanip> #include <unordered_set> #include <stack> #include <ext/pb_ds/assoc_container.hpp> #include <random> #include <chrono> #include <bitset> #include <complex> // usings using namespace std; using namespace __gnu_pbds; // misc #define ll long long #define ld long double #define pb push_back #define pq priority_queue #define ub upper_bound #define lb lower_bound template <typename T, typename U> bool emin(T &a, const U &b) { return b < a ? a = b, true : false; } template <typename T, typename U> bool emax(T &a, const U &b) { return b > a ? a = b, true : false; } typedef uint64_t hash_t; // vectors #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vpii vector<pair<int, int>> #define vvpii vector<vector<pair<int, int>>> #define vppipi vector<pair<int, pair<int, int>>> #define vl vector<ll> #define vvl vector<vl> #define vvvl vector<vvl> #define vpll vector<pair<ll, ll>> #define vvpll vector<vpll> #define vb vector<bool> #define vvb vector<vb> #define vs vector<string> #define sz(x) (int)x.size() #define rz resize #define all(x) x.begin(), x.end() #define vc vector<char> #define vvc vector<vc> // pairs #define pii pair<int, int> #define pll pair<ll, ll> #define mp make_pair #define f first #define s second // sets #define si set<int> #define sl set<ll> #define ss set<string> #define in insert template <class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // maps #define mii map<int, int> #define mll map<ll, ll> // loops #define FR(x, z, y) for (int x = z; x < y; x++) #define FRE(x, z, y) FR(x, z, y + 1) #define F(x, y) FR(x, 0, y) #define FE(x, y) F(x, y + 1) #define A(x, y) for (auto &x : y) struct TwoEdgeCC { struct { vi a; void init(int n) { a = vi(n, -1); } int get(int x) { return a[x] < 0 ? x : a[x] = get(a[x]); } bool merge(int x, int y) { x = get(x), y = get(y); if(x == y) return false; a[x] += a[y]; a[y] = x; return true; } } dsu; int n; vvi a; vi d, p; vpii e; void init(int tn) { n = tn, a = vvi(n), d = vi(n), p = vi(n, -1), dsu.init(tn); } void dfs(int x) { A(u, a[x]) if(u != p[x]) p[u] = x, d[u] = d[x] + 1, dfs(u); } void ae(int x, int y) { if(dsu.merge(x, y)) a[x].pb(y), a[y].pb(x); else e.pb({x, y}); } void ad(int x, int y) { while(true) { x = dsu.get(x), y = dsu.get(y); if(x == y) return; if(d[x] < d[y]) swap(x, y); dsu.merge(p[x], x); } } void go() { F(i, n) if(p[i] == -1) dfs(i); dsu.init(n); A(u, e) ad(u.f, u.s); } }; int n, m; vpii v; TwoEdgeCC a; int main() { cin >> n >> m; a.init(n); v = vpii(m); A(u, v) { cin >> u.f >> u.s; a.ae(--u.f, --u.s); } a.go(); A(u, v) if(a.dsu.get(u.f) != a.dsu.get(u.s)) cout << u.f + 1 << " " << u.s + 1 << endl; }
#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...