Submission #293027

# Submission time Handle Problem Language Result Execution time Memory
293027 2020-09-07T15:38:31 Z TAMREF None (balkan16_acrobat) C++11
100 / 100
485 ms 43088 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]);
	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: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 7 ms 8576 KB Output is correct
2 Correct 7 ms 8576 KB Output is correct
3 Correct 8 ms 8516 KB Output is correct
4 Correct 6 ms 8576 KB Output is correct
5 Correct 7 ms 8552 KB Output is correct
6 Correct 7 ms 8576 KB Output is correct
7 Correct 6 ms 8552 KB Output is correct
8 Correct 6 ms 8576 KB Output is correct
9 Correct 7 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 7 ms 8576 KB Output is correct
4 Correct 8 ms 8576 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 6 ms 8576 KB Output is correct
7 Correct 7 ms 8576 KB Output is correct
8 Correct 10 ms 8576 KB Output is correct
9 Correct 6 ms 7424 KB Output is correct
10 Correct 7 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 7 ms 8704 KB Output is correct
14 Correct 8 ms 8576 KB Output is correct
15 Correct 7 ms 8704 KB Output is correct
16 Correct 8 ms 8576 KB Output is correct
17 Correct 8 ms 8576 KB Output is correct
18 Correct 8 ms 8704 KB Output is correct
19 Correct 8 ms 8704 KB Output is correct
20 Correct 8 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8576 KB Output is correct
2 Correct 8 ms 8576 KB Output is correct
3 Correct 8 ms 8576 KB Output is correct
4 Correct 8 ms 8576 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 7 ms 8576 KB Output is correct
7 Correct 9 ms 8576 KB Output is correct
8 Correct 7 ms 8576 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 7 ms 8576 KB Output is correct
11 Correct 7 ms 7424 KB Output is correct
12 Correct 9 ms 8704 KB Output is correct
13 Correct 7 ms 8700 KB Output is correct
14 Correct 7 ms 8576 KB Output is correct
15 Correct 7 ms 8716 KB Output is correct
16 Correct 7 ms 8576 KB Output is correct
17 Correct 7 ms 8576 KB Output is correct
18 Correct 7 ms 8704 KB Output is correct
19 Correct 7 ms 8680 KB Output is correct
20 Correct 7 ms 8576 KB Output is correct
21 Correct 373 ms 24236 KB Output is correct
22 Correct 485 ms 38668 KB Output is correct
23 Correct 184 ms 29088 KB Output is correct
24 Correct 82 ms 10364 KB Output is correct
25 Correct 87 ms 10716 KB Output is correct
26 Correct 191 ms 20584 KB Output is correct
27 Correct 97 ms 11896 KB Output is correct
28 Correct 79 ms 11132 KB Output is correct
29 Correct 325 ms 43088 KB Output is correct
30 Correct 276 ms 41040 KB Output is correct
31 Correct 76 ms 11004 KB Output is correct
32 Correct 282 ms 42076 KB Output is correct
33 Correct 7 ms 8704 KB Output is correct
34 Correct 8 ms 8704 KB Output is correct
35 Correct 373 ms 24196 KB Output is correct
36 Correct 75 ms 10616 KB Output is correct
37 Correct 7 ms 8704 KB Output is correct
38 Correct 8 ms 8704 KB Output is correct