답안 #967619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967619 2024-04-22T14:11:21 Z steveonalex Pipes (CEOI15_pipes) C++17
40 / 100
768 ms 45748 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
 
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b){a = b; return true;}
        return false;
    }
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b){a = b; return true;}
        return false;
    }
template <class T>
    void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
        for(auto i: a) out << i << separator;
        out << finish;
    }
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

struct DSU{
    int n;
    vector<int> parent, sz;

    DSU(int _n){
        n = _n;
        parent.resize(n+1); sz.resize(n+1, 1);
        for(int i = 0; i<=n; ++i) parent[i] = i;
    }

    int find_set(int u){return (u == parent[u]) ? u : (parent[u] = find_set(parent[u]));}
    bool same_set(int u,int v){return find_set(u) == find_set(v);}

    bool join_set(int u, int v){
        u = find_set(u), v = find_set(v);
        if (u != v){
            if (sz[u] < sz[v]) swap(u, v);
            parent[v] = u;
            sz[u] += sz[v];
            return true;
        }
        return false;
    }
};

const int N = 1e5 + 69;
vector<int> graph[N], chode[N];
int num[N], low[N];
int dfs_cnt = 0;

void tarjan(int u, int p){
    num[u] = low[u] = ++dfs_cnt;
    for(int v: graph[u]){
        if (v == p){p = -1; continue;}
        if (num[v]) minimize(low[u], num[v]);
        else{
            tarjan(v, u);
            minimize(low[u], low[v]);
            if (low[v] >= num[v]){
                cout << u << " " << v << "\n";
            }
        }
    }
}

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m; cin >> n >> m;
    DSU mst1(n), mst2(n);
    for(int i = 1; i<=m; ++i){
        int u, v; cin >> u >> v;
        // if (i <= n-1) u = i, v = rngesus(i+1, n);
        // else u = rngesus(1, n-1), v = rngesus(u+1, n);
        if (mst1.join_set(u, v)){
            graph[u].push_back(v);
            graph[v].push_back(u);
        }
        else{
            mst2.join_set(u, v);
        }
    }

    for(int i = 1; i<=n; ++i) if (mst2.sz[mst2.find_set(i)] > 1)
        chode[mst2.find_set(i)].push_back(i);

    for(int i = 1; i<=n; ++i) if (chode[i].size() >= 2){
        for(int j = 0; j < chode[i].size(); ++j){
            int k = (j + 1) % chode[i].size();
            int u = chode[i][j], v = chode[i][k];
            graph[u].push_back(v);
            graph[v].push_back(u);
        }
    }

    for(int i = 1; i<=n; ++i) if (num[i] == 0) tarjan(i, i);

    return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:113:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |         for(int j = 0; j < chode[i].size(); ++j){
      |                        ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6244 KB Output is correct
2 Correct 4 ms 5980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 5956 KB Output is correct
2 Correct 69 ms 5908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 6736 KB Output is correct
2 Correct 135 ms 6228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 8400 KB Output is correct
2 Runtime error 172 ms 22096 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 250 ms 14028 KB Output is correct
2 Runtime error 221 ms 28760 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 387 ms 14916 KB Output is correct
2 Runtime error 388 ms 45748 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 517 ms 17100 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 632 ms 23872 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 768 ms 36556 KB Memory limit exceeded
2 Halted 0 ms 0 KB -