#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
vector<int> adj[MAXN]; // Danh sách kề
bool visited[MAXN];
int parent[MAXN]; // Lưu đỉnh cha trong DFS
vector<pair<int, int>> directedEdges; // Danh sách cạnh có hướng
int n, m, t;
// DFS kiểm tra liên thông mạnh
void dfs(int u) {
visited[u] = true;
for (int v : adj[u]) {
if (!visited[v]) dfs(v);
}
}
// Kiểm tra đồ thị có định chiều được không
bool isStronglyOrientable() {
// Kiểm tra liên thông
fill(visited, visited + n + 1, false);
dfs(1);
if (count(visited + 1, visited + n + 1, true) != n) return false;
// Kiểm tra liên thông trên đồ thị ngược
vector<int> reverseAdj[MAXN];
for (int u = 1; u <= n; u++) {
for (int v : adj[u]) {
reverseAdj[v].push_back(u);
}
}
fill(visited, visited + n + 1, false);
swap(adj, reverseAdj);
dfs(1);
swap(adj, reverseAdj);
return count(visited + 1, visited + n + 1, true) == n;
}
// Định chiều đồ thị sử dụng DFS
void orientGraph(int u) {
visited[u] = true;
for (int v : adj[u]) {
if (!visited[v]) {
parent[v] = u;
directedEdges.emplace_back(u, v);
orientGraph(v);
} else if (parent[u] != v) {
directedEdges.emplace_back(u, v); // Chọn hướng còn lại
}
}
}
int main() {
cin >> t >> n >> m;
vector<pair<int, int>> edges(m);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
edges[i] = {u, v};
}
if (t == 1) {
cout << (isStronglyOrientable() ? 1 : 0) << endl;
} else if (t == 2) {
fill(visited, visited + n + 1, false);
fill(parent, parent + n + 1, -1);
orientGraph(1);
sort(directedEdges.begin(), directedEdges.end());
cout << n << " " << m << endl;
for (auto [u, v] : directedEdges) {
cout << u << " " << v << endl;
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTUFYTiA9IDEwNTsKdmVjdG9yPGludD4gYWRqW01BWE5dOyAgLy8g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