Submission #623836

# Submission time Handle Problem Language Result Execution time Memory
623836 2022-08-06T15:36:56 Z Alma Pipes (CEOI15_pipes) C++17
10 / 100
5000 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
using ll = long long;
using ii = pair<int,int>;

const int INF = 1e9;
const ll LLINF = 1e18;
using vi = vector<int>;
using vvi = vector<vi>;

void setIO (string fileName) {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    if (fileName != "std") {
        freopen((fileName + ".in").c_str(), "r", stdin);
        freopen((fileName + ".out").c_str(), "w", stdout);
    }
}

vi st, path, par;
vvi adj;

int uFind(int u) {
	if (par[u] == u) return u;
	return par[u] = uFind(par[u]);
}

void uJoin (int u, int v) {
	int a = uFind(u), b = uFind(v);
	par[a] = b;
}

void dfs (int u, int p) {
	st[u] = 1;
	path.push_back(u);
	for (auto v: adj[u]) {
		if (v == p) continue;
		if (st[v] == 1) {
			for (int i = (int)path.size()-1; i >= 0; i--) {
				if (path[i] == v) break;
				uJoin(v, path[i]);
			}
		}
		if (st[v] == 0) dfs(v, u);
	}
	path.pop_back();
	st[u] = 2;
}

void dfs2 (int u, int p) {
	st[u] = 1;
	for (auto v: adj[u]) {
		if (v == p) continue;
		if (uFind(u) != uFind(v))
			cout << u+1 << ' ' << v+1 << '\n';
		if (st[v] == 0) dfs2(v, u);
	}
}

int main() {
    setIO("std");

    int n, m, u, v;
	cin >> n >> m;

	adj = vvi(n);
	st = vi(n, 0);
	par = vi(n);

	for (int i = 0; i < n; i++)
		par[i] = i;
	
	while (m--) {
		cin >> u >> v;
		u--; v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	for (int i = 0; i < n; i++) {
		if (st[i] == 0) dfs(i, -1);
	}
	st = vi(n, 0);
	
	for (int i = 0; i < n; i++) {
		if (st[i] == 0) dfs2(i, -1);
	}

    return 0;
}

Compilation message

pipes.cpp: In function 'void setIO(std::string)':
pipes.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen((fileName + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pipes.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((fileName + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1104 KB Output is correct
2 Incorrect 10 ms 684 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3818 ms 8948 KB Output is correct
2 Correct 606 ms 7920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5029 ms 12680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5047 ms 24772 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5055 ms 31320 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5068 ms 65056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5035 ms 65536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3196 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1712 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -