답안 #97597

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97597 2019-02-17T12:15:51 Z dalgerok Pipes (CEOI15_pipes) C++14
60 / 100
1389 ms 20432 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 1e5 + 1, M = 6e6 + 1;



int n, m;
int p[2][N];
int tin[N], fup[N], timer;
bitset < N > used;
bitset < M > usd;
vector < int > g[N], e[N];

int dsu_get(int x, int v){
    return p[x][v] == v ? v : p[x][v] = dsu_get(x, p[x][v]);
}

void dfs(int v, int pr = 0){
    tin[v] = fup[v] = ++timer;
    used[v] = true;
    for(int i = 0; i < (int)g[v].size(); i++){
        int to = g[v][i], ind = e[v][i];
        if(ind == pr){
            continue;
        }
        if(!used[to]){
            dfs(to, ind);
            if(fup[to] > tin[v]){
                if(!usd[ind]){
                    usd[ind] = true;
                    cout << v << " " << to << "\n";
                }
            }
            fup[v] = min(fup[v], fup[to]);
        }
        else{
            fup[v] = min(fup[v], tin[to]);
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        p[0][i] = p[1][i] = i;
    }
    for(int i = 1; i <= m; i++){
        int x, y;
        cin >> x >> y;
        if(dsu_get(0, x) == dsu_get(0, y)){
            if(dsu_get(1, x) == dsu_get(1, y)){
                continue;
            }
            p[1][dsu_get(1, x)] = dsu_get(1, y);
        }
        else{
            p[0][dsu_get(0, x)] = dsu_get(0, y);
        }
        g[x].push_back(y);
        e[x].push_back(i);
        g[y].push_back(x);
        e[y].push_back(i);
    }
    for(int i = 1; i <= n; i++){
        if(!used[i]){
            dfs(i);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 5804 KB Output is correct
2 Correct 11 ms 5504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 5544 KB Output is correct
2 Correct 100 ms 5376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 6588 KB Output is correct
2 Correct 193 ms 6048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 298 ms 8728 KB Output is correct
2 Correct 260 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 537 ms 15896 KB Output is correct
2 Correct 479 ms 12516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 790 ms 17432 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1022 ms 20432 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1238 ms 20396 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1389 ms 19568 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -