Submission #1021699

# Submission time Handle Problem Language Result Execution time Memory
1021699 2024-07-13T02:54:48 Z idiotcomputer Pipes (CEOI15_pipes) C++11
0 / 100
697 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz size 
 
const int mxN = 1e5;
int n,m;

int p[2*mxN];

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;
	int cnt = 0;
	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;
		cnt++;
	}
	if (cnt > 2*n-2) while(true) continue;
	cout << cnt << '\n';
	return 0;	
}
 
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 604 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 5716 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 101 ms 10112 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 174 ms 16724 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 223 ms 21596 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 356 ms 34088 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 490 ms 44884 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 574 ms 56404 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 697 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -