Submission #669022

# Submission time Handle Problem Language Result Execution time Memory
669022 2022-12-05T11:51:46 Z radinr85 Pipes (CEOI15_pipes) C++14
20 / 100
906 ms 12724 KB
//radinr85
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef deque<int> dq;
typedef long double ld;
typedef pair<int , int> pii;
typedef priority_queue<int> pq;

const int maxn = 3e6;
const ll mod = 1e9+7;

#define F first
#define S second
#define endl "\n"
#define pb push_back
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

const int N = 1e5 + 1;
vector<int> ver[N];
int par[N][2];
bool mark[N];
int cnt[N];
int n , m;

int get_par(int u , int x) {
    return par[u][x] == u ? u : par[u][x] = get_par(par[u][x] , x);
}
bool merge(int u , int v , int x) {
    u = get_par(u , x);
    v = get_par(v , x);

    if(u == v)
        return false;
    
    par[u][x] = v;

    return true;
}
int DFS(int u) {
    mark[u] = true;

    for(auto v : ver[u]) {
        if(!mark[v]) {
            par[v][0] = u;
            par[v][1] = par[u][1] + 1;
            cnt[u] += DFS(v);
        }
        else if(par[u][1] - par[v][1] > 1) {
            cnt[u] ++;
            cnt[v] --;
        }
    }
    if(cnt[u] == 0 && par[u][0] != 0)
        cout << u << " " << par[u][0] << endl;
    
    return cnt[u];
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
    cin >> n >> m;
    for(int i = 1 ; i <= n ; i ++)
        par[i][0] = i , par[i][1] = i;
    for(int i = 0 ; i < m ; i ++) {
        int u , v;
        cin >> u >> v;

        if(merge(u , v , 0)) {
            ver[u].pb(v);
            ver[v].pb(u);
        }
        else if(merge(u , v , 1)) {
            ver[u].pb(v);
            ver[v].pb(u);
        }
    }
    ms(par , 0);
    for(int i = 1 ; i <= n ; i ++) {
        if(!mark[i]) {
            DFS(i);
        }
    }

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Incorrect 2 ms 3412 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3760 KB Output is correct
2 Incorrect 5 ms 3668 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 3732 KB Output is correct
2 Incorrect 77 ms 3608 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 136 ms 4292 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 227 ms 5600 KB Output is correct
2 Correct 186 ms 5364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 324 ms 9960 KB Output is correct
2 Incorrect 265 ms 7044 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 467 ms 10948 KB Output is correct
2 Incorrect 443 ms 8396 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 613 ms 12724 KB Output is correct
2 Incorrect 589 ms 8616 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 745 ms 12620 KB Output is correct
2 Incorrect 699 ms 8560 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 906 ms 12236 KB Output is correct
2 Correct 845 ms 9784 KB Output is correct