답안 #292850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292850 2020-09-07T14:12:33 Z TAMREF Acrobat (balkan16_acrobat) C++17
100 / 100
463 ms 41680 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", 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]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8576 KB Output is correct
2 Correct 7 ms 8576 KB Output is correct
3 Correct 7 ms 8576 KB Output is correct
4 Correct 7 ms 8560 KB Output is correct
5 Correct 7 ms 8552 KB Output is correct
6 Correct 8 ms 8576 KB Output is correct
7 Correct 7 ms 8576 KB Output is correct
8 Correct 8 ms 8576 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 7 ms 8576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8576 KB Output is correct
2 Correct 7 ms 8576 KB Output is correct
3 Correct 6 ms 8576 KB Output is correct
4 Correct 8 ms 8576 KB Output is correct
5 Correct 6 ms 8576 KB Output is correct
6 Correct 8 ms 8576 KB Output is correct
7 Correct 8 ms 8576 KB Output is correct
8 Correct 7 ms 8628 KB Output is correct
9 Correct 6 ms 7424 KB Output is correct
10 Correct 8 ms 8576 KB Output is correct
11 Correct 9 ms 7424 KB Output is correct
12 Correct 7 ms 8704 KB Output is correct
13 Correct 7 ms 8608 KB Output is correct
14 Correct 6 ms 8576 KB Output is correct
15 Correct 9 ms 8704 KB Output is correct
16 Correct 8 ms 8576 KB Output is correct
17 Correct 9 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
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8576 KB Output is correct
2 Correct 7 ms 8576 KB Output is correct
3 Correct 8 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 7 ms 8608 KB Output is correct
7 Correct 7 ms 8576 KB Output is correct
8 Correct 8 ms 8576 KB Output is correct
9 Correct 7 ms 7424 KB Output is correct
10 Correct 6 ms 8576 KB Output is correct
11 Correct 8 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 8 ms 8592 KB Output is correct
15 Correct 8 ms 8704 KB Output is correct
16 Correct 6 ms 8576 KB Output is correct
17 Correct 8 ms 8576 KB Output is correct
18 Correct 7 ms 8704 KB Output is correct
19 Correct 8 ms 8680 KB Output is correct
20 Correct 6 ms 8576 KB Output is correct
21 Correct 366 ms 24256 KB Output is correct
22 Correct 463 ms 37592 KB Output is correct
23 Correct 175 ms 27744 KB Output is correct
24 Correct 55 ms 10360 KB Output is correct
25 Correct 67 ms 10744 KB Output is correct
26 Correct 202 ms 20268 KB Output is correct
27 Correct 95 ms 11900 KB Output is correct
28 Correct 85 ms 11048 KB Output is correct
29 Correct 387 ms 41680 KB Output is correct
30 Correct 247 ms 39760 KB Output is correct
31 Correct 87 ms 11008 KB Output is correct
32 Correct 357 ms 40848 KB Output is correct
33 Correct 7 ms 8704 KB Output is correct
34 Correct 7 ms 8704 KB Output is correct
35 Correct 407 ms 24392 KB Output is correct
36 Correct 82 ms 10568 KB Output is correct
37 Correct 9 ms 8680 KB Output is correct
38 Correct 8 ms 8704 KB Output is correct