# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1022278 | vjudge1 | Pipes (CEOI15_pipes) | C++17 | 785 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |