답안 #294131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
294131 2020-09-08T15:47:29 Z 송준혁(#5802) Acrobat (balkan16_acrobat) C++17
100 / 100
541 ms 59212 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, M;
int U[303030], V[303030], X[303030];
int dfn[303030], num, D[303030], R;
vector<int> P[303030], C;
vector<pii> adj[303030];
vector<pii> O1, O2;

void tr(int u){
	dfn[u] = 1;
	for (pii v : adj[u]) if (!dfn[v.fi]) X[v.se] = 1, tr(v.fi);
}

bool dfs(int u){
	dfn[u] = ++num;
	bool a=false;
	for (pii v : adj[u]){
		if ((dfn[v.fi] && dfn[v.fi]<dfn[u]) || !X[v.se]) continue;
		if (!dfn[v.fi]){
			if (dfs(v.fi)){
				if (U[v.se] == u) O1.pb(pii(u, v.fi));
				continue;
			}
		}
		if (U[v.se] == v.fi) O1.pb(pii(v.fi, u));
		if (a) a = false;
		else a = true;
	}
	return a;
}

int main(){
	scanf("%d %d", &N, &M);
	for (int i=1; i<=M; i++){
		scanf("%d %d", &U[i], &V[i]);
		adj[U[i]].pb(pii(V[i], i));
		if (U[i] != V[i]) adj[V[i]].pb(pii(U[i], i));
		P[U[i]].pb(i), D[V[i]]++;
	}
	for (int i=1; i<=N; i++) if (!dfn[i]) tr(i);
	for (int i=1; i<=N; i++){
		int a=0;
		for (int u : P[i]){
			if (X[u]) continue;
			if (!a) a = u;
			else a = 0;
		}
		if (a) X[a] = 1;
	}
	memset(dfn, 0, sizeof dfn);
	for (int i=1; i<=N; i++) if (!dfn[i]){
		if (dfs(i)) return !printf("-1\n");
	}
	for (int i=1; i<N; i++) O2.pb(pii(i, i+1));
	O2.pb(pii(N, 1));
	for (pii t : O1) D[t.fi]++, D[t.se]--;
	int a=0;
	for (int i=1; i<=N; i++) if (D[i]&1){
		if (a) O2.pb(pii(a, i)), a=0;
		else a = i;
	}
	printf("%d\n", (int)O1.size()+(int)O2.size());
	for (pii t : O1) printf("1 %d %d\n", t.fi, t.se);
	for (pii t : O2) printf("2 %d %d\n", t.fi, t.se);
	return 0;
}

Compilation message

main.cpp: In function 'int main()':
main.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |  scanf("%d %d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |   scanf("%d %d", &U[i], &V[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 15744 KB Output is correct
2 Correct 11 ms 15744 KB Output is correct
3 Correct 11 ms 15744 KB Output is correct
4 Correct 12 ms 15744 KB Output is correct
5 Correct 12 ms 15744 KB Output is correct
6 Correct 13 ms 15744 KB Output is correct
7 Correct 11 ms 15744 KB Output is correct
8 Correct 12 ms 15744 KB Output is correct
9 Correct 11 ms 15744 KB Output is correct
10 Correct 12 ms 15744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 15744 KB Output is correct
2 Correct 11 ms 15744 KB Output is correct
3 Correct 12 ms 15744 KB Output is correct
4 Correct 11 ms 15744 KB Output is correct
5 Correct 13 ms 15744 KB Output is correct
6 Correct 11 ms 15744 KB Output is correct
7 Correct 12 ms 15744 KB Output is correct
8 Correct 11 ms 15744 KB Output is correct
9 Correct 12 ms 15744 KB Output is correct
10 Correct 11 ms 15744 KB Output is correct
11 Correct 13 ms 15872 KB Output is correct
12 Correct 12 ms 15872 KB Output is correct
13 Correct 12 ms 15872 KB Output is correct
14 Correct 11 ms 15872 KB Output is correct
15 Correct 12 ms 15872 KB Output is correct
16 Correct 11 ms 15872 KB Output is correct
17 Correct 11 ms 15872 KB Output is correct
18 Correct 12 ms 15872 KB Output is correct
19 Correct 11 ms 15872 KB Output is correct
20 Correct 13 ms 15744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 15744 KB Output is correct
2 Correct 11 ms 15744 KB Output is correct
3 Correct 11 ms 15744 KB Output is correct
4 Correct 11 ms 15872 KB Output is correct
5 Correct 11 ms 15744 KB Output is correct
6 Correct 11 ms 15744 KB Output is correct
7 Correct 11 ms 15744 KB Output is correct
8 Correct 11 ms 15744 KB Output is correct
9 Correct 11 ms 15744 KB Output is correct
10 Correct 12 ms 15744 KB Output is correct
11 Correct 11 ms 15872 KB Output is correct
12 Correct 12 ms 15872 KB Output is correct
13 Correct 12 ms 15872 KB Output is correct
14 Correct 11 ms 15744 KB Output is correct
15 Correct 12 ms 15944 KB Output is correct
16 Correct 11 ms 15872 KB Output is correct
17 Correct 12 ms 15744 KB Output is correct
18 Correct 12 ms 15872 KB Output is correct
19 Correct 12 ms 15872 KB Output is correct
20 Correct 11 ms 15744 KB Output is correct
21 Correct 541 ms 46188 KB Output is correct
22 Correct 485 ms 50912 KB Output is correct
23 Correct 128 ms 27868 KB Output is correct
24 Correct 72 ms 24952 KB Output is correct
25 Correct 86 ms 26360 KB Output is correct
26 Correct 332 ms 42344 KB Output is correct
27 Correct 152 ms 29320 KB Output is correct
28 Correct 117 ms 30072 KB Output is correct
29 Correct 314 ms 59212 KB Output is correct
30 Correct 298 ms 56448 KB Output is correct
31 Correct 122 ms 27000 KB Output is correct
32 Correct 358 ms 57836 KB Output is correct
33 Correct 12 ms 15872 KB Output is correct
34 Correct 13 ms 15872 KB Output is correct
35 Correct 534 ms 46184 KB Output is correct
36 Correct 104 ms 28152 KB Output is correct
37 Correct 12 ms 15872 KB Output is correct
38 Correct 12 ms 15872 KB Output is correct