Submission #1151812

#TimeUsernameProblemLanguageResultExecution timeMemory
1151812AbdullahIshfaqMake them Meet (EGOI24_makethemmeet)C++20
70 / 100
6 ms5212 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 998244353
const int N = 200005;
vector<int> g[N];
int p[N], dep[N];
void dfs(int u, int v = -1){
	for(auto c : g[u]){
		if(c == v){
			continue;
		}
		dep[c] = dep[u] + 1;
		p[c] = u;
		dfs(c, u);
	}
}
void solve(){
	ll n, m, u , v;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	if(m == n - 1){
		cout << 2 * n << '\n';
		dfs(0);
		for(int i = 0 ;i < 2 * n ; i++){
			for(int j = 0; j < n; j++){
				if(dep[j] % 2 == i % 2){
					cout << j << " ";
				}
				else if(j == 0){
					cout << g[j][0] << " ";
				}
				else{
					cout << p[j] << " ";
				}
			}
			cout << '\n';
		}
	}
	else{
		cout << n << '\n';
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cout << (j + (i % 2)) / 2 << ' ';
			}
			cout << '\n';
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int tests = 1;
	// cin >> tests;
	for(int i = 1; i <= tests; i ++)
		solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...