Submission #388513

# Submission time Handle Problem Language Result Execution time Memory
388513 2021-04-11T19:08:38 Z armanmohammadi Pipes (CEOI15_pipes) C++14
50 / 100
1374 ms 65536 KB
/*
 _________        .---"""      """---.
:______.-':      :  .--------------.  :
| ______  |      | :                : |
|:______B:|      | |  Little Error: | |
|:______B:|      | |                | |
|:______B:|      | |  Power not     | |
|         |      | |  found.        | |
|:_____:  |      | |                | |
|    ==   |      | :                : |
|       O |      :  '--------------'  :
|       o |      :'---...______...---'
|       o |-._.-i___/'             \._
|'-.____o_|   '-.   '-...______...-'  `-._
:_________:      `.____________________   `-.___.-.
                 .'.eeeeeeeeeeeeeeeeee.'.      :___:
    fsc        .'.eeeeeeeeeeeeeeeeeeeeee.'.
              :____________________________:
*/




//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n"
#define X first
#define Y second
#define pii pair<int,int>
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));}


int par[maxn][2] ;
int mark[maxn] ;
int an;
vector<int>adj[maxn];
int n ;
int m ;
int getPar(int v){
	if(par[v][an] == v){
		return v ;
	}else return par[v][an] = getPar(par[v][an]);
}
 
bool merge(int u, int v){
    u = getPar(u);
	v = getPar(v);
    if (u == v){
    	return false;
	}
    par[u][an] = v;
    return true;
}
 
void dfs(int v, int p = 0){
    mark[v] = 1;
    par[v][1] = maxn;
    int cnt = 0 ;
    for (int u : adj[v]){
        if (u == p){
            cnt ++;
            continue;
        }
        if (mark[u]){
        	par[v][1] = min(par[v][1], par[u][0]);
		}
        else{
            par[u][0] = par[v][0] + 1;
            dfs(u, v);
            par[v][1] = min(par[v][1], par[u][1]);
        }
    }
    if (p and cnt == 1 and par[p][0] < par[v][1]){
    	cout << p << " " << v << endl;
	}
}
 
int main(){
    migmig ; 
    cin >> n >> m;
    for (int i = 0; i < maxn; i ++){
    	par[i][0] = par[i][1] = i;
	}    
    for (int i = 0; i < m; i ++){
        int u ;
		int v ;
		bool flag = true;
        cin >> u >> v;
		an = 0;
        if (merge(u, v)){
            adj[u].pb(v);
            adj[v].pb(u);
            flag = 0;
        }
        an = 1;
        if (flag and merge(u, v)){
            adj[u].pb(v);
            adj[v].pb(u);
        }
    }memset(par, 0, sizeof par);
    for (int v = 1; v <= n; v ++){
    	if (!mark[v]){
    		dfs(v);
		}  
	}
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3788 KB Output is correct
2 Correct 6 ms 3708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 3708 KB Output is correct
2 Correct 109 ms 3572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 4208 KB Output is correct
2 Correct 223 ms 3820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 5548 KB Output is correct
2 Correct 266 ms 5184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 447 ms 9848 KB Output is correct
2 Runtime error 400 ms 25228 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 659 ms 10784 KB Output is correct
2 Runtime error 659 ms 41756 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 953 ms 12776 KB Output is correct
2 Runtime error 897 ms 49924 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 1090 ms 12560 KB Output is correct
2 Runtime error 1168 ms 61540 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 1374 ms 12092 KB Output is correct
2 Runtime error 1299 ms 65536 KB Memory limit exceeded