# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
293845 |
2020-09-08T13:00:03 Z |
반딧불(#5811) |
None (balkan16_acrobat) |
C++17 |
|
36 ms |
30976 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void massert(bool cond){
if(!cond){
printf("-1");
exit(0);
}
}
struct Answer{
int a, b, c;
Answer(){}
Answer(int a, int b, int c): a(a), b(b), c(c){}
};
vector<Answer> ans;
int n, m;
int edgeX[300002], edgeY[300002];
vector<int> linkDual[300002];
int degA[300002], degB[300002];
bool visited[300002];
int group[300002], groupNum, groupRoot[300002];
int DP[300002];
vector<int> spanningChild[300002];
unordered_set<int> edgeSet[300002];
void dfs(int x){
visited[x] = 1, group[x] = groupNum;
for(auto y: linkDual[x]){
if(visited[y]) continue;
dfs(y);
spanningChild[x].push_back(y);
}
}
void dfs2(int x){
for(auto y: spanningChild[x]){
dfs2(y);
DP[x] += DP[y];
if(DP[y]%2==1){
if(edgeSet[x].find(y) != edgeSet[x].end()) ans.push_back({1, x, y}), degA[x]--, degB[x]++, degA[y]++, degB[y]--;
else ans.push_back({1, y, x}), degA[y]--, degB[y]++, degA[x]++, degB[x]--;
}
}
}
int main(){
scanf("%d %d", &n, &m);
for(int i=1; i<=m; i++){
int x, y;
scanf("%d %d", &x, &y);
edgeX[i] = x, edgeY[i] = y;
linkDual[x].push_back(y), linkDual[y].push_back(x);
edgeSet[x].insert(y);
degA[x]++, degB[y]++;
}
for(int i=1; i<=n; i++){
if(!visited[i]){
groupRoot[++groupNum] = i;
dfs(i);
}
}
vector<pair<int, int> > degAVec;
for(int i=1; i<=n; i++){
if(degA[i]%2 == 1) degAVec.push_back({group[i], i});
}
sort(degAVec.begin(), degAVec.end());
massert(degAVec.size() % 2 == 0);
for(int i=0; i<(int)degAVec.size(); i+=2){
massert(group[degAVec[i].first] == group[degAVec[i+1].first]);
DP[degAVec[i].second]++, DP[degAVec[i+1].second]++;
}
for(int i=1; i<=groupNum; i++){
dfs2(groupRoot[i]);
}
vector<int> oddB;
for(int i=1; i<=n; i++) if(degB[i]%2) oddB.push_back(i);
massert(oddB.size() % 2 == 0);
sort(oddB.begin(), oddB.end());
if(oddB.size() == 2 && oddB.back() - oddB.front() == 1){
for(int i=1; i<n; i++) if(i != oddB.front()) ans.push_back({2, i, i+1});
ans.push_back({2, n, 1});
}
else{
int ts = (int)oddB.size() / 2;
for(int i=0; i<ts; i++) ans.push_back({2, oddB[i], oddB[i+ts]});
for(int i=1; i<n; i++) ans.push_back({2, i, i+1});
ans.push_back({2, n, 1});
}
assert((int)ans.size() <= n*n);
printf("%d\n", (int)ans.size());
for(int i=0; i<(int)ans.size(); i++){
printf("%d %d %d\n", ans[i].a, ans[i].b, ans[i].c);
}
}
Compilation message
main.cpp: In function 'int main()':
main.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
54 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
57 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
30944 KB |
Output is correct |
2 |
Correct |
26 ms |
30848 KB |
Output is correct |
3 |
Correct |
26 ms |
30848 KB |
Output is correct |
4 |
Correct |
27 ms |
30848 KB |
Output is correct |
5 |
Correct |
24 ms |
30848 KB |
Output is correct |
6 |
Correct |
22 ms |
30848 KB |
Output is correct |
7 |
Correct |
22 ms |
30848 KB |
Output is correct |
8 |
Correct |
22 ms |
30976 KB |
Output is correct |
9 |
Incorrect |
24 ms |
30976 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
30848 KB |
Output is correct |
2 |
Correct |
22 ms |
30848 KB |
Output is correct |
3 |
Correct |
33 ms |
30848 KB |
Output is correct |
4 |
Correct |
23 ms |
30848 KB |
Output is correct |
5 |
Correct |
22 ms |
30848 KB |
Output is correct |
6 |
Correct |
26 ms |
30848 KB |
Output is correct |
7 |
Correct |
31 ms |
30848 KB |
Output is correct |
8 |
Correct |
24 ms |
30976 KB |
Output is correct |
9 |
Incorrect |
23 ms |
30848 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
30848 KB |
Output is correct |
2 |
Correct |
27 ms |
30888 KB |
Output is correct |
3 |
Correct |
23 ms |
30848 KB |
Output is correct |
4 |
Correct |
23 ms |
30848 KB |
Output is correct |
5 |
Correct |
25 ms |
30848 KB |
Output is correct |
6 |
Correct |
36 ms |
30840 KB |
Output is correct |
7 |
Correct |
28 ms |
30896 KB |
Output is correct |
8 |
Correct |
23 ms |
30848 KB |
Output is correct |
9 |
Incorrect |
25 ms |
30976 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |