Submission #669024

# Submission time Handle Problem Language Result Execution time Memory
669024 2022-12-05T11:53:25 Z radinr85 Pipes (CEOI15_pipes) C++14
20 / 100
895 ms 12684 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 3796 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 84 ms 3736 KB Output is correct
2 Incorrect 76 ms 3600 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 155 ms 4280 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 242 ms 5600 KB Output is correct
2 Correct 211 ms 5292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 316 ms 9876 KB Output is correct
2 Incorrect 321 ms 7072 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 578 ms 10896 KB Output is correct
2 Incorrect 471 ms 8416 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 667 ms 12596 KB Output is correct
2 Incorrect 590 ms 8616 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 828 ms 12684 KB Output is correct
2 Incorrect 718 ms 8628 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 895 ms 12188 KB Output is correct
2 Correct 871 ms 9768 KB Output is correct