Submission #868144

# Submission time Handle Problem Language Result Execution time Memory
868144 2023-10-30T13:41:18 Z Cookie Pipes (CEOI15_pipes) C++14
0 / 100
9 ms 8536 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("HCN.INP");
ofstream fout("HCN.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
//using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 9;
const int mxn = 1e5 + 5, mxq = 2e5 + 5, sq = 200, mxv = 2e6 + 5;
const ll inf = 1e17 + 5;
//const int base= (1 << 18);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
struct DSU{
    int pa[mxn + 1];
    int fp(int u){
        if(pa[u] < 0)return(u);
        return(pa[u] = fp(pa[u]));
    }
    bool unon(int u, int v){
        u = fp(u); v = fp(v);
        if(u == v)return(0);
        if(abs(pa[u]) < abs(pa[v]))swap(u, v);
        pa[u] += pa[v]; pa[v] = u;
    }
    void init(){
        for(int i = 1; i <= n; i++)pa[i] = -1;
    }
};
DSU norma, cool;
vt<pii>adj[mxn + 1];
vt<pii>res;
int num[mxn + 1], low[mxn + 1], tt = 0;
bool used[mxn + 1];
void dfs(int s){
    num[s] = low[s] = ++tt;
    for(auto [v, id]: adj[s]){
        if(used[id])continue;
        used[id] = 1;
        if(!num[v]){
            dfs(v);
            if(low[v] > num[s]){
                res.pb({s, v});
            }
            low[s] = min(low[s], low[v]);
        }else{
            low[s] = min(low[s], num[v]);
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n >> m;
    norma.init(); cool.init();
    int id = 0;
    for(int i = 0; i < m; i++){
        int u, v; cin >> u >> v;
        if(norma.unon(u, v)){
            id++;
            adj[u].pb({v, id}); adj[v].pb({u, id});
        }else if(cool.unon(u, v)){
            id++;
            adj[u].pb({v, id}); adj[v].pb({u, id});
        }
    }
    for(int i = 1; i <= n; i++){
        if(!num[i]){
            dfs(i);
        }
    }
    
    for(auto [u, v]: res)cout << u << ' ' << v << "\n";
    return(0);
}

Compilation message

pipes.cpp: In function 'void dfs(int)':
pipes.cpp:51:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |     for(auto [v, id]: adj[s]){
      |              ^
pipes.cpp: In function 'int main()':
pipes.cpp:87:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   87 |     for(auto [u, v]: res)cout << u << ' ' << v << "\n";
      |              ^
pipes.cpp: In member function 'bool DSU::unon(int, int)':
pipes.cpp:38:31: warning: control reaches end of non-void function [-Wreturn-type]
   38 |         pa[u] += pa[v]; pa[v] = u;
      |                         ~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 6748 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 7000 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 7004 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 7000 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 7260 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 8000 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 8028 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 8536 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 8300 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 8280 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -