Submission #1022278

#TimeUsernameProblemLanguageResultExecution timeMemory
1022278vjudge1Pipes (CEOI15_pipes)C++17
40 / 100
785 ms65536 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...