#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
int n, m;
int g[111][111];
int G[111][111];
int cnt = 0;
void rev(int x, int p, int c) {
if(c == 1) {
for(int i=1; i<=n; i++) {
if(!g[x][i]) continue;
g[i][x]++;
g[x][i]--;
rev(i, x, 3-c);
}
}
else {
for(int i=1; i<=n; i++) {
if(!g[i][x]) continue;
g[x][i]++;
g[i][x]--;
rev(i, x, 3-c);
}
}
}
int main() {
fast;
cin >> n >> m;
for(int i=1; i<=m; i++) {
int a, b;
cin >> a >> b;
G[a][b] = g[a][b] = 1;
if(a == b) {
cout << -1;
return 0;
}
}
for(int i=1; i<=n; i++) {
int cnt = 0, k = 0;
for(int j=1; j<=n; j++) {
if(g[i][j] & 1) cnt++;
}
if(cnt & 1) {
rev(i, i, 1);
}
}
vector<pii> ans;
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
if(g[i][j] < G[i][j]) {
ans.eb(i, j);
}
}
}
cout << ans.size() + n << "\n";
for(auto i : ans) {
cout << 1 << " " << i.fi << " " << i.se << "\n";
}
for(int i=1; i<=n; i++) {
cout << 2 << " " << i << " " << (i == n ? 1 : i + 1) << "\n";
}
}
Compilation message
main.cpp: In function 'int main()':
main.cpp:61:16: warning: unused variable 'k' [-Wunused-variable]
61 | int cnt = 0, k = 0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |