Submission #496697

# Submission time Handle Problem Language Result Execution time Memory
496697 2021-12-21T22:21:25 Z aryan12 Pipes (CEOI15_pipes) C++17
40 / 100
336 ms 24724 KB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
 
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
 
const int N = 7e4 + 5;
int par[2][N];
vector<int> g[N];
int disc[N], low[N], tim = 0;
bool vis[N];
 
void dfs(int node, int parent) {
	vis[node] = true;
	disc[node] = ++tim;
	low[node] = tim;
	bool flag = false;
	for(int i = 0; i < g[node].size(); i++) {
		if(g[node][i] == parent && !flag) {
			flag = true;
			continue;
		}
		if(vis[g[node][i]]) {
			low[node] = min(low[node], disc[g[node][i]]);
		}
		else {
			dfs(g[node][i], node);
			low[node] = min(low[node], low[g[node][i]]);
			if(low[g[node][i]] > disc[node]) {
				cout << node << " " << g[node][i] << "\n";
			}
		}
	}
}
 
int Find(int x, int d) {
	if(par[d][x] == x) {
		return x;
	}
	return par[d][x] = Find(par[d][x], d);
}
 
void Unite(int u, int v, int d) {
	v = Find(v, d), u = Find(u, d);
	par[d][v] = u;
}
 
void Solve() {
	int n, m;
	cin >> n >> m;
	for(int i = 0; i <= n; i++) {
		par[0][i] = i;
		par[1][i] = i;
	}
	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		if(Find(u, 0) != Find(v, 0)) {
			Unite(u, v, 0);
			g[u].push_back(v);
			g[v].push_back(u);
		}
		else if(Find(u, 1) != Find(v, 1)) {
			Unite(u, v, 1);
			g[u].push_back(v);
			g[v].push_back(u);
		}
	}
	for(int i = 1; i <= n; i++) {
		if(!vis[i]) {
			dfs(i, -1);
		}
	}
}
 
int32_t main() {
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}

Compilation message

pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i = 0; i < g[node].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2380 KB Output is correct
2 Correct 5 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 2260 KB Output is correct
2 Correct 78 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 3060 KB Output is correct
2 Correct 157 ms 2540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 225 ms 4660 KB Output is correct
2 Runtime error 223 ms 18184 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 336 ms 9928 KB Output is correct
2 Runtime error 295 ms 24724 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 4812 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 4812 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 4940 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 4940 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -