Submission #1021720

# Submission time Handle Problem Language Result Execution time Memory
1021720 2024-07-13T03:12:38 Z idiotcomputer Pipes (CEOI15_pipes) C++11
50 / 100
781 ms 47492 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz size 
 
const int mxN = 1e5;
int n,m;

vector<int> adj[mxN];
int p[2*mxN];
 
void dfs(int c, int depth, int par){
	p[c] = depth;
	p[c+n] = p[c];
	int op = par;
	for (int i : adj[c]){
		if (i == par){par = -1; continue;}
		if (p[i] != -1){ p[c+n] = min(p[c+n],p[i]); continue;}
		dfs(i,depth+1,c);
		p[c+n] = min(p[c+n], p[i+n]);
	}
	if (p[c+n] >= depth && op != -1) cout << c+1 << " " << op+1 << '\n';
}
 

int gpar(const int &c){
	if (p[c] == c) return c;
	p[c] = gpar(p[c]);
	return p[c];
}

bool ss(const int &a, const int &b){
	return gpar(a) == gpar(b);
}

void un(const int &a, const int &b){
	p[gpar(a)] = gpar(b);
}

 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 
	cin >> n >> m;
	for (int i = 0; i < 2* n; i++) p[i] = i;
 
	int a,b;
	for (int i = 0; i < m; i++){
		cin >> a >> b;
		a -= 1;
		b -= 1;
		if (!ss(a,b)) un(a,b);
		else if (!ss(a+n,b+n)) un(a+n,b+n);
		else continue;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	for (int i = 0; i < n; i++) p[i] = -1;
	for (int i = 0; i < n; i++) if (p[i] == -1) dfs(i,0,-1);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3420 KB Output is correct
2 Correct 4 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 6224 KB Output is correct
2 Correct 59 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 8680 KB Output is correct
2 Correct 124 ms 9260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 13780 KB Output is correct
2 Correct 152 ms 11924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 278 ms 20544 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 404 ms 28248 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 509 ms 35596 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 635 ms 41196 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 781 ms 47492 KB Memory limit exceeded
2 Halted 0 ms 0 KB -