# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
293912 | 2020-09-08T13:43:19 Z | 문홍윤(#5819) | None (balkan16_acrobat) | C++17 | 193 ms | 262148 KB |
#include <bits/stdc++.h> #define mp make_pair #define eb emplace_back #define F first #define S second #define all(x) x.begin(), x.end() #define svec(x) sort(all(x)) #define press(x) x.erase(unique(all(x)), x.end()); using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<int, LL> pil; typedef pair<LL, int> pli; typedef pair<LL, LL> pll; const int INF=1e9; const LL LLINF=1e18; struct UNION_FIND{ int par[3010]; void init(){for(int i=1; i<=3000; i++)par[i]=i;} int findpar(int num){return num==par[num]?num:par[num]=findpar(par[num]);} void mergepar(int a, int b){par[a]=b;} }uf; int n, m, cnt[3010]; pii lin[3010]; vector<pii> link[3010]; vector<int> bip[3010]; vector<pair<int, pii> > ans; bool ch[3010]; int dfs(int num, int par){ ch[num]=true; int ret=cnt[num]; for(auto i:link[num]){ if(i.F==par)continue; if(dfs(i.F, num)){ ans.eb(1, lin[i.S]); swap(lin[i.S].F, lin[i.S].S); ret++; } } return ret%2; } int main(){ scanf("%d %d", &n, &m); uf.init(); for(int i=1; i<=m; i++){ scanf("%d %d", &lin[i].F, &lin[i].S); cnt[lin[i].F]++; if(uf.findpar(lin[i].F)!=uf.findpar(lin[i].S)){ uf.mergepar(lin[i].F, lin[i].S); link[lin[i].F].eb(lin[i].S, i); link[lin[i].S].eb(lin[i].F, i); } } for(int i=1; i<=n; i++){ if(ch[i])continue; if(dfs(i, 0))return !printf("-1"); } for(int i=1; i<=m; i++)bip[lin[i].F].eb(lin[i].S); uf.init(); memset(cnt, 0, sizeof cnt); for(int i=1; i<=n; i++){ if(!bip[i].size())continue; for(int j=0; j<bip[i].size(); j+=2){ uf.mergepar(bip[i][j], bip[i][j+1]); } for(auto j:bip[i])cnt[j]++; } for(int i=1; i<=n; i++){ if(uf.findpar(1)!=uf.findpar(i)){ uf.mergepar(1, i); ans.eb(2, mp(1, i)); cnt[1]++; cnt[i]++; } } int nop=0; for(int i=1; i<=n; i++){ if(cnt[i]%2==0)continue; if(nop){ ans.eb(2, mp(nop, i)); nop=0; } else nop=i; } printf("%d\n", ans.size()); for(auto i:ans)printf("%d %d %d\n", i.F, i.S.F, i.S.S); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 186 ms | 262148 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 193 ms | 262148 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 181 ms | 262148 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |