Submission #125429

# Submission time Handle Problem Language Result Execution time Memory
125429 2019-07-05T09:47:58 Z eriksuenderhauf Pipes (CEOI15_pipes) C++11
100 / 100
1668 ms 12680 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int MAXN = 1e5 + 5;
vector<int> adj[MAXN];
int cnt = 1, par[MAXN], par2[MAXN], lo[MAXN];

int qry(int x) { return x == par[x] ? x : par[x] = qry(par[x]); }
void join(int u, int v) { u = qry(u), v = qry(v); par[u] = v; }

int qry2(int x) { return x == par2[x] ? x : par2[x] = qry2(par2[x]); }
void join2(int u, int v) { u = qry2(u), v = qry2(v); par2[u] = v; }

void dfs(int u, int p) {
	par[u] = lo[u] = cnt++;
	while (!adj[u].empty()) {
		int v = adj[u].back();
		adj[u].pop_back();
		if (!par[v]) {
			dfs(v, u);
			lo[u] = min(lo[u], lo[v]);
			if (lo[v] > par[u] && qry2(u) != qry2(v))
				printf("%d %d\n", u, v);
		} else if (v != p)
			lo[u] = min(lo[u], par[v]);
	}
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++)
		par[i] = par2[i] = i;
	for (int i = 0; i < m; i++) {
		int u, v; scanf("%d %d", &u, &v);
		if (qry2(u) == qry2(v))
			continue;
		if (qry(u) == qry(v)) {
			adj[u].pb(v);
			adj[v].pb(u);
			join2(u, v);
			continue;
		}
		join(u, v);
		adj[u].pb(v);
		adj[v].pb(u);
	}
	for (int i = 1; i <= n; i++)
		par[i] = 0;
	for (int i = 1; i <= n; i++)
		if (!par[i])
			dfs(i, 0);
    return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:36:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int u, v; scanf("%d %d", &u, &v);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3164 KB Output is correct
2 Correct 9 ms 2984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 3840 KB Output is correct
2 Correct 134 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 237 ms 4380 KB Output is correct
2 Correct 279 ms 3792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 390 ms 5568 KB Output is correct
2 Correct 340 ms 5328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 559 ms 9868 KB Output is correct
2 Correct 493 ms 6780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 870 ms 11276 KB Output is correct
2 Correct 809 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1132 ms 12220 KB Output is correct
2 Correct 1075 ms 8596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1382 ms 12680 KB Output is correct
2 Correct 1310 ms 8500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1668 ms 12084 KB Output is correct
2 Correct 1563 ms 9408 KB Output is correct