답안 #680264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680264 2023-01-10T10:54:15 Z peijar Pipes (CEOI15_pipes) C++17
80 / 100
932 ms 65536 KB
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <utility>
#include <cmath>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <iomanip>
#include <bitset>
using namespace std;
const int maxn=1e5+2;
int parent[maxn];
int parent2[maxn];
//int sz[maxn];
//int sz2[maxn];
bitset<maxn>seen;
int st[maxn];
//int parent3[maxnn];
int lowest[maxn];
int tmm=0;
vector<int> N[maxn];
//vector<pair<int, int>>t1;
//vector<pair<int, int>>t2;
//map<pair<int, int>, int>sss;
int x,y;
int get_root(int v){
    if (parent[v]!=v){
        parent[v]=get_root(parent[v]);
    }
    return parent[v];
}
int get_root2(int v){
    if (parent2[v]!=v){
        parent2[v]=get_root2(parent2[v]);
    }
    return parent2[v];
}
bool Union(int u,int v){
    u=get_root(u);
    v=get_root(v);
    if (u==v){
        return 1;
    }
    parent[u]=v;
    return 0;
}
bool Union2(int u,int v){
    x=u;
    y=v;
    u=get_root2(u);
    v=get_root2(v);
    if (u==v){
        return 0;
    }
    N[x].push_back(y);
    N[y].push_back(x);
    parent2[u]=v;
    return 1;
}
void dfs(int node,int pp){
    seen[node]=1;
    tmm+=1;
    st[node]=tmm;
    lowest[node]=tmm;
    //stft.push_back(node);
    for (int n: N[node]){
        if (seen[n]!=1){
            //parent3[n]=node;
            dfs(n,node);
            lowest[node]=min(lowest[node], lowest[n]);
            if (lowest[n]>st[node] && count(N[node].begin(),N[node].end(),n)==1){
                cout << node << ' ' << n << "\n";
            }
        }
        else if (n!=pp){
            lowest[node]=min(lowest[node],st[n]);
        }
    }
    //ft[node]=t;
    //stft.push_back(node);
}
//const int M = 1000000007;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    for (int i=1;i<n+1;i++){
        parent[i]=i;
        //sz[i]=1;
    }
    for (int i=1;i<n+1;i++){
        parent2[i]=i;
        //sz2[i]=1;
    }
    int u,v;
    for (int i=0;i<m;i++){
        cin >> u >> v;
        if (Union(u, v)){
            Union2(u, v);
        }
        else{
            N[u].push_back(v);
            N[v].push_back(u);
        }
    }
    for (int i=1;i<n+1;i++){
        if (seen[i]!=1){
            dfs(i,-1);
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3328 KB Output is correct
2 Correct 5 ms 3076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 3628 KB Output is correct
2 Correct 80 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 4444 KB Output is correct
2 Correct 156 ms 3772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 6256 KB Output is correct
2 Correct 192 ms 7080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 314 ms 11372 KB Output is correct
2 Correct 281 ms 7376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 481 ms 13008 KB Output is correct
2 Correct 477 ms 9452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 641 ms 15312 KB Output is correct
2 Correct 598 ms 9352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 787 ms 17296 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 932 ms 14812 KB Output is correct
2 Runtime error 920 ms 65536 KB Memory limit exceeded
3 Halted 0 ms 0 KB -