# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
294119 |
2020-09-08T15:41:21 Z |
송준혁(#5802) |
None (balkan16_acrobat) |
C++17 |
|
13 ms |
15872 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));
R = u;
continue;
}
}
if (U[v.se] == v.fi) O1.pb(pii(v.fi, u));
R = v.fi;
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]){
R = 0;
if (dfs(i)) return !printf("-1\n");
if (R) C.pb(R);
}
if (C.size()>1){
for (int i=0; i<C.size()-1; i++) O2.pb(pii(C[i], C[i+1]));
O2.pb(pii(C[0], C.back()));
}
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;
}
assert(!a);
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:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i=0; i<C.size()-1; i++) O2.pb(pii(C[i], C[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:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
44 | scanf("%d %d", &U[i], &V[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
11 ms |
15744 KB |
Output is correct |
6 |
Correct |
11 ms |
15744 KB |
Output is correct |
7 |
Correct |
13 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 |
11 ms |
15744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
11 ms |
15744 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 |
15872 KB |
Output is correct |
9 |
Correct |
12 ms |
15744 KB |
Output is correct |
10 |
Correct |
11 ms |
15744 KB |
Output is correct |
11 |
Correct |
11 ms |
15872 KB |
Output is correct |
12 |
Incorrect |
12 ms |
15872 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
15744 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 |
11 ms |
15744 KB |
Output is correct |
11 |
Correct |
12 ms |
15872 KB |
Output is correct |
12 |
Incorrect |
12 ms |
15872 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |