Submission #1062125

# Submission time Handle Problem Language Result Execution time Memory
1062125 2024-08-16T19:29:25 Z trMatherz Pipes (CEOI15_pipes) C++17
40 / 100
1952 ms 65536 KB
#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 DSU{ 
        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; 
        }
    } ; 
struct TwoEdgeCC {
    DSU 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; 
DSU v1, v2; 
int main() {
    cin >> n >> m; a.init(n); v1.init(n); v2.init(n); 
    F(i, m){
        int x, y; cin >> x >> y; x--; y--; 
        if(v1.merge(x, y)) a.ae(x, y), v.pb({x, y}); 
        else if(v2.merge(x, y)) a.ae(x, y); 
    }
    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 time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 892 KB Output is correct
2 Correct 4 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 604 KB Output is correct
2 Correct 166 ms 5968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 1372 KB Output is correct
2 Correct 342 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 452 ms 2508 KB Output is correct
2 Runtime error 414 ms 16824 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 623 ms 7112 KB Output is correct
2 Runtime error 568 ms 25028 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 943 ms 28872 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1281 ms 53704 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1615 ms 65220 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1952 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -