Submission #1022278

# Submission time Handle Problem Language Result Execution time Memory
1022278 2024-07-13T11:50:04 Z vjudge1 Pipes (CEOI15_pipes) C++17
40 / 100
785 ms 65536 KB
#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 1e5 + 2;
const ll mod = 1e9 + 7;
const ll base1 = 31;
ll 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];
        dp[u] %= mod;
    }
    if(dp[u] == 0 && p != -1)cout << u << ' ' << p << '\n';
}
void solve() {
    int n, m;
    cin >> n >> m;
    memset(par , -1 , sizeof(par));
    ll b1 = 1;
    for(int i = 1; i <= m ;i ++){
        int u , v;
        cin >> u >> v;
        b1 *= base1;
        b1 %= mod;
        if(union_set(u , v)){
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        else{
            dp[u] += b1;
            dp[v] = (dp[v] + mod - b1) % mod;
            dp[u] %= mod;
        }
    }
    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:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen(_ "inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
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(_ "out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3420 KB Output is correct
2 Correct 5 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 8544 KB Output is correct
2 Correct 73 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 13144 KB Output is correct
2 Correct 149 ms 14688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 200 ms 20048 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 224 ms 26520 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 356 ms 39508 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 462 ms 50772 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 592 ms 62456 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 785 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -