답안 #294076

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
294076 2020-09-08T14:59:47 Z moven(#5824) Acrobat (balkan16_acrobat) C++17
100 / 100
420 ms 41684 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] && 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;
    assert(ans.size() <= 2 * n);
	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:73:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for(int i=0; i<v.size(); i+=2) ans.emplace_back(2, v[i], v[i+1]);
      |               ~^~~~~~~~~
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from main.cpp:1:
main.cpp:75:23: 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]
   75 |     assert(ans.size() <= 2 * n);
      |            ~~~~~~~~~~~^~~~~~~~
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 6 ms 8608 KB Output is correct
2 Correct 6 ms 8608 KB Output is correct
3 Correct 6 ms 8576 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
# 결과 실행 시간 메모리 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 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
11 Correct 6 ms 7424 KB Output is correct
12 Correct 7 ms 8704 KB Output is correct
13 Correct 6 ms 8704 KB Output is correct
14 Correct 6 ms 8576 KB Output is correct
15 Correct 6 ms 8704 KB Output is correct
16 Correct 7 ms 8576 KB Output is correct
17 Correct 6 ms 8576 KB Output is correct
18 Correct 6 ms 8704 KB Output is correct
19 Correct 6 ms 8704 KB Output is correct
20 Correct 6 ms 8576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 5 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 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
11 Correct 6 ms 7424 KB Output is correct
12 Correct 7 ms 8704 KB Output is correct
13 Correct 6 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 6 ms 8704 KB Output is correct
19 Correct 6 ms 8704 KB Output is correct
20 Correct 7 ms 8576 KB Output is correct
21 Correct 343 ms 24432 KB Output is correct
22 Correct 420 ms 37592 KB Output is correct
23 Correct 158 ms 27736 KB Output is correct
24 Correct 53 ms 10360 KB Output is correct
25 Correct 66 ms 10748 KB Output is correct
26 Correct 185 ms 20548 KB Output is correct
27 Correct 94 ms 11896 KB Output is correct
28 Correct 78 ms 11128 KB Output is correct
29 Correct 244 ms 41684 KB Output is correct
30 Correct 228 ms 39760 KB Output is correct
31 Correct 80 ms 11128 KB Output is correct
32 Correct 271 ms 40920 KB Output is correct
33 Correct 7 ms 8704 KB Output is correct
34 Correct 6 ms 8704 KB Output is correct
35 Correct 328 ms 24276 KB Output is correct
36 Correct 76 ms 10808 KB Output is correct
37 Correct 7 ms 8704 KB Output is correct
38 Correct 6 ms 8704 KB Output is correct