Submission #293953

# Submission time Handle Problem Language Result Execution time Memory
293953 2020-09-08T14:05:27 Z TAMREF None (balkan16_acrobat) C++11
100 / 100
563 ms 49348 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
 
struct disj{
	int pa[600005];
	void init(int n){
		iota(pa, pa + n + 1, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}disj;
 
int n, m, cnt[300005], sum;
int s[300005], e[300005], vis[300005];
vector<pi> gph[300005];
vector<int> v;
vector<tuple<int, int, int>> ans;
 
int dfs(int x, int p){
	vis[x] = 1;
	int ret = cnt[x];
	for(auto &i : gph[x]){
		if(i.second != p && dfs(i.second, x)){
			ans.emplace_back(1, s[i.first], e[i.first]);
			swap(s[i.first], e[i.first]);
			ret ^= 1;
		}
	}
	return ret;
}
 
int main(){
	scanf("%d %d",&n,&m);
	disj.init(n);
	for(int i=0; i<m; i++){
		scanf("%d %d",&s[i],&e[i]); 
		cnt[s[i]] ^= 1;
		if(disj.uni(s[i], e[i])){
			gph[s[i]].push_back(pi(i, e[i]));
			gph[e[i]].push_back(pi(i, s[i]));
		}
	}
	for(int i=1; i<=n; i++){
		if(!vis[i]){
			if(dfs(i, -1)){
				puts("-1");
				return 0;
			}
		}
	}
	memset(cnt, 0, sizeof(cnt));
	disj.init(2*n);
	for(int i=0; i<m; i++){
		disj.uni(s[i] + n, e[i]);
		cnt[e[i]] ^= 1;
	}
	for(int i=2; i<=n; i++){
		if(disj.uni(1, i)){
			ans.emplace_back(2, 1, i);
			cnt[1] ^= 1;
			cnt[i] ^= 1;
		}
	}
	v.clear();
	for(int i=1; i<=n; i++) if(cnt[i]) v.push_back(i);
	for(int i=0; i<v.size(); i+=2) ans.emplace_back(2, v[i], v[i+1]);
  	while(ans.size() < 5 * n / 2) ans.emplace_back(2, 1, 1);
	cout << ans.size() << endl;
	for(auto &i : ans) printf("%d %d %d\n\n\n\n", get<0>(i), get<1>(i), get<2>(i));
}

Compilation message

main.cpp: In function 'int main()':
main.cpp:75:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  for(int i=0; i<v.size(); i+=2) ans.emplace_back(2, v[i], v[i+1]);
      |               ~^~~~~~~~~
main.cpp:76:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   76 |    while(ans.size() < 5 * n / 2) ans.emplace_back(2, 1, 1);
      |          ~~~~~~~~~~~^~~~~~~~~~~
main.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |  scanf("%d %d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~
main.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |   scanf("%d %d",&s[i],&e[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8576 KB Output is correct
2 Correct 6 ms 8576 KB Output is correct
3 Correct 6 ms 8576 KB Output is correct
4 Correct 7 ms 8576 KB Output is correct
5 Correct 6 ms 8576 KB Output is correct
6 Correct 6 ms 8576 KB Output is correct
7 Correct 6 ms 8576 KB Output is correct
8 Correct 6 ms 8576 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 6 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8576 KB Output is correct
2 Correct 6 ms 8576 KB Output is correct
3 Correct 6 ms 8576 KB Output is correct
4 Correct 6 ms 8576 KB Output is correct
5 Correct 7 ms 8576 KB Output is correct
6 Correct 6 ms 8576 KB Output is correct
7 Correct 6 ms 8576 KB Output is correct
8 Correct 6 ms 8576 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 6 ms 8576 KB Output is correct
11 Correct 6 ms 7424 KB Output is correct
12 Correct 7 ms 8704 KB Output is correct
13 Correct 8 ms 8704 KB Output is correct
14 Correct 6 ms 8576 KB Output is correct
15 Correct 7 ms 8704 KB Output is correct
16 Correct 6 ms 8576 KB Output is correct
17 Correct 6 ms 8576 KB Output is correct
18 Correct 7 ms 8704 KB Output is correct
19 Correct 7 ms 8704 KB Output is correct
20 Correct 7 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8576 KB Output is correct
2 Correct 6 ms 8576 KB Output is correct
3 Correct 6 ms 8608 KB Output is correct
4 Correct 6 ms 8576 KB Output is correct
5 Correct 6 ms 8576 KB Output is correct
6 Correct 6 ms 8576 KB Output is correct
7 Correct 6 ms 8576 KB Output is correct
8 Correct 6 ms 8576 KB Output is correct
9 Correct 6 ms 7424 KB Output is correct
10 Correct 6 ms 8576 KB Output is correct
11 Correct 6 ms 7424 KB Output is correct
12 Correct 7 ms 8704 KB Output is correct
13 Correct 8 ms 8704 KB Output is correct
14 Correct 6 ms 8576 KB Output is correct
15 Correct 8 ms 8832 KB Output is correct
16 Correct 6 ms 8576 KB Output is correct
17 Correct 6 ms 8576 KB Output is correct
18 Correct 7 ms 8704 KB Output is correct
19 Correct 7 ms 8704 KB Output is correct
20 Correct 6 ms 8576 KB Output is correct
21 Correct 343 ms 24296 KB Output is correct
22 Correct 563 ms 46284 KB Output is correct
23 Correct 252 ms 35912 KB Output is correct
24 Correct 60 ms 10360 KB Output is correct
25 Correct 75 ms 10872 KB Output is correct
26 Correct 221 ms 23520 KB Output is correct
27 Correct 105 ms 12212 KB Output is correct
28 Correct 92 ms 11256 KB Output is correct
29 Correct 326 ms 49348 KB Output is correct
30 Correct 306 ms 46804 KB Output is correct
31 Correct 89 ms 11160 KB Output is correct
32 Correct 372 ms 48184 KB Output is correct
33 Correct 11 ms 8704 KB Output is correct
34 Correct 7 ms 8704 KB Output is correct
35 Correct 360 ms 24248 KB Output is correct
36 Correct 89 ms 10616 KB Output is correct
37 Correct 7 ms 8704 KB Output is correct
38 Correct 7 ms 8704 KB Output is correct