답안 #868151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868151 2023-10-30T13:47:17 Z Cookie Pipes (CEOI15_pipes) C++14
50 / 100
730 ms 65536 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;
        return(1);
    }
    void init(){
        for(int i = 1; i <= n; i++)pa[i] = -1;
    }
};
DSU norma, cool;
vt<int>adj[mxn + 1];
int edge[2 * mxn + 1];
vt<pii>res;
int num[mxn + 1], low[mxn + 1], tt = 0;
bool used[2 * mxn + 1];
void dfs(int s){
    num[s] = low[s] = ++tt;
    for(auto id: adj[s]){
        if(used[id])continue;
        used[id] = 1;
        int v = edge[id] ^ s;
        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(id); adj[v].pb(id);
            edge[id] = u ^ v;
        }else if(cool.unon(u, v)){
            id++;
            adj[u].pb(id); adj[v].pb(id);
            edge[id] = u ^ v;
        }
    }
    assert(id <= 2 * n);
    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 'int main()':
pipes.cpp:93:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   93 |     for(auto [u, v]: res)cout << u << ' ' << v << "\n";
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 4716 KB Output is correct
2 Correct 68 ms 4712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 5460 KB Output is correct
2 Correct 130 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 6992 KB Output is correct
2 Correct 154 ms 6836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 11780 KB Output is correct
2 Runtime error 216 ms 26456 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 372 ms 12860 KB Output is correct
2 Runtime error 378 ms 43484 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 477 ms 15064 KB Output is correct
2 Runtime error 474 ms 51468 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 651 ms 15060 KB Output is correct
2 Runtime error 586 ms 63060 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 729 ms 14548 KB Output is correct
2 Runtime error 730 ms 65536 KB Memory limit exceeded
3 Halted 0 ms 0 KB -