답안 #1026981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026981 2024-07-18T16:25:12 Z vjudge1 Pipes (CEOI15_pipes) C++17
10 / 100
647 ms 61128 KB
#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 1e5;
vector < int > adj[N + 2];
struct dsu{
    int par[N + 2];
    int find_par(const int &u){
        if(par[u] < 0)return u;
        par[u] = find_par(par[u]);
        return par[u];
    }
    bool union_set(int u , int v){
        u = find_par(u);
        v = find_par(v);
        if(u != v){
            if(par[u] > par[v])swap(u , v);
            par[u] += par[v];
            par[v] = u;
            return true;
        }
        return false;
    }

} par1 , par2;
int timer = 0;
void dfs(int &u , int &p){
    par1.par[u] = par2.par[u] = ++timer;
    for(int &v:adj[u]){
        if(v == p) continue;
        if(!par2.par[v]){
            dfs(v , u);
            par1.par[u] = min(par1.par[u] , par1.par[v]);
            if(par1.par[v] == par2.par[v]) cout << u << " " << v <<'\n';
        }
        else par1.par[u] = min(par1.par[u] , par2.par[v]);

    }
}
void solve() {
    int n , m;
    cin >> n >> m;
    memset(par1.par , -1 , sizeof(par1.par));
    memset(par2.par , -1 , sizeof(par2.par));
    for(int i = 1; i <= m ;i ++){
        int u , v;
        cin >> u >> v;
        if(par1.union_set(u , v)){
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        else if(par2.union_set(u , v)){
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
    }
    memset(par2.par , 0 , sizeof(par2.par));
    for(int i = 1; i <= n ; i++){
        if(!par2.par[i])dfs(i , i);
    }
    
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    #define _ "maxseq."
    if (fopen(_ "inp", "r")) {
        freopen(_ "inp", "r", stdin);
        freopen(_ "out", "w", stdout);
    }
    
    solve();
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(_ "inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
pipes.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(_ "out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Incorrect 1 ms 3420 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3932 KB Output is correct
2 Incorrect 3 ms 3676 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 3676 KB Output is correct
2 Incorrect 60 ms 3672 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 93 ms 4436 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 5712 KB Output is correct
2 Correct 131 ms 5348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 10320 KB Output is correct
2 Incorrect 156 ms 6732 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 11344 KB Output is correct
2 Incorrect 281 ms 8360 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 418 ms 13212 KB Output is correct
2 Runtime error 413 ms 29264 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 525 ms 13140 KB Output is correct
2 Runtime error 549 ms 61128 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 647 ms 12736 KB Output is correct
2 Runtime error 589 ms 18512 KB Memory limit exceeded
3 Halted 0 ms 0 KB -