답안 #1022311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1022311 2024-07-13T11:59:20 Z vjudge1 Pipes (CEOI15_pipes) C++17
30 / 100
721 ms 59300 KB
#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 1e5 + 2;
int  dp[N + 2];
int par[N + 2];
vector < int > adj[N + 2];
int find_par(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;
}
void dfs(int u , int p ){
    par[u] = 1;
    for(auto v: adj[u]){
        if(par[v])continue;
        dfs(v , u);
        dp[u] ^= dp[v];
    }
    if(dp[u] == 0 && p != -1)cout << u << ' ' << p << '\n';
}
void solve() {
    int n, m;
    cin >> n >> m;
    memset(par , -1 , sizeof(par));
    for(int i = 1; i <= m ;i ++){
        int u , v;
        cin >> u >> v;
        if(union_set(u , v)){
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        else{
            dp[u] ^= i;
            dp[v] ^= i;
        }
    }
    memset(par , 0 , sizeof(par));
    for(int i = 1; i <= n ; i ++){
        if(!par[i])dfs(i , -1);
    }
    
}

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:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(_ "inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
pipes.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(_ "out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3364 KB Output is correct
2 Incorrect 4 ms 3160 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 3164 KB Output is correct
2 Correct 79 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 3524 KB Output is correct
2 Correct 121 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 192 ms 4012 KB Output is correct
2 Runtime error 155 ms 17904 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 246 ms 5468 KB Output is correct
2 Runtime error 201 ms 23636 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 342 ms 5972 KB Output is correct
2 Runtime error 361 ms 39236 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 515 ms 6480 KB Output is correct
2 Runtime error 446 ms 47924 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 558 ms 6696 KB Output is correct
2 Runtime error 592 ms 59300 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 721 ms 16724 KB Memory limit exceeded
2 Halted 0 ms 0 KB -