Submission #293930

# Submission time Handle Problem Language Result Execution time Memory
293930 2020-09-08T13:48:47 Z 문홍윤(#5819) None (balkan16_acrobat) C++17
100 / 100
487 ms 48004 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[300010];
    void init(){for(int i=1; i<=300000; 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[findpar(a)]=findpar(b);}
}uf;

int n, m, cnt[300010];
pii lin[300010];
vector<pii> link[300010];
vector<int> bip[300010];
vector<pair<int, pii> > ans;
bool ch[300010];

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

main.cpp: In function 'int main()':
main.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for(int j=0; j<bip[i].size(); j+=2){
      |                      ~^~~~~~~~~~~~~~
main.cpp:89:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wformat=]
   89 |     printf("%d\n", ans.size());
      |             ~^     ~~~~~~~~~~
      |              |             |
      |              int           std::vector<std::pair<int, std::pair<int, int> > >::size_type {aka long unsigned int}
      |             %ld
main.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |         scanf("%d %d", &lin[i].F, &lin[i].S);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16768 KB Output is correct
2 Correct 12 ms 16768 KB Output is correct
3 Correct 13 ms 16768 KB Output is correct
4 Correct 13 ms 16768 KB Output is correct
5 Correct 12 ms 16768 KB Output is correct
6 Correct 13 ms 16768 KB Output is correct
7 Correct 12 ms 16768 KB Output is correct
8 Correct 12 ms 16768 KB Output is correct
9 Correct 11 ms 15616 KB Output is correct
10 Correct 14 ms 16768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16800 KB Output is correct
2 Correct 14 ms 16928 KB Output is correct
3 Correct 12 ms 16768 KB Output is correct
4 Correct 12 ms 16768 KB Output is correct
5 Correct 12 ms 16708 KB Output is correct
6 Correct 12 ms 16768 KB Output is correct
7 Correct 12 ms 16768 KB Output is correct
8 Correct 12 ms 16768 KB Output is correct
9 Correct 11 ms 15616 KB Output is correct
10 Correct 12 ms 16768 KB Output is correct
11 Correct 12 ms 15616 KB Output is correct
12 Correct 13 ms 16896 KB Output is correct
13 Correct 14 ms 16896 KB Output is correct
14 Correct 13 ms 16768 KB Output is correct
15 Correct 13 ms 16896 KB Output is correct
16 Correct 16 ms 16768 KB Output is correct
17 Correct 13 ms 16768 KB Output is correct
18 Correct 13 ms 16896 KB Output is correct
19 Correct 13 ms 16896 KB Output is correct
20 Correct 12 ms 16768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16768 KB Output is correct
2 Correct 12 ms 16768 KB Output is correct
3 Correct 13 ms 16800 KB Output is correct
4 Correct 12 ms 16800 KB Output is correct
5 Correct 12 ms 16768 KB Output is correct
6 Correct 12 ms 16768 KB Output is correct
7 Correct 12 ms 16768 KB Output is correct
8 Correct 12 ms 16768 KB Output is correct
9 Correct 11 ms 15616 KB Output is correct
10 Correct 12 ms 16768 KB Output is correct
11 Correct 12 ms 15616 KB Output is correct
12 Correct 13 ms 16896 KB Output is correct
13 Correct 13 ms 16896 KB Output is correct
14 Correct 12 ms 16768 KB Output is correct
15 Correct 13 ms 16896 KB Output is correct
16 Correct 12 ms 16768 KB Output is correct
17 Correct 12 ms 16768 KB Output is correct
18 Correct 13 ms 16896 KB Output is correct
19 Correct 13 ms 16896 KB Output is correct
20 Correct 12 ms 16768 KB Output is correct
21 Correct 364 ms 30448 KB Output is correct
22 Correct 487 ms 45272 KB Output is correct
23 Correct 184 ms 30296 KB Output is correct
24 Correct 72 ms 19832 KB Output is correct
25 Correct 83 ms 20476 KB Output is correct
26 Correct 208 ms 28780 KB Output is correct
27 Correct 109 ms 21880 KB Output is correct
28 Correct 95 ms 21496 KB Output is correct
29 Correct 273 ms 48004 KB Output is correct
30 Correct 250 ms 46092 KB Output is correct
31 Correct 93 ms 20856 KB Output is correct
32 Correct 302 ms 45404 KB Output is correct
33 Correct 13 ms 16896 KB Output is correct
34 Correct 14 ms 16896 KB Output is correct
35 Correct 348 ms 30576 KB Output is correct
36 Correct 90 ms 18680 KB Output is correct
37 Correct 15 ms 16896 KB Output is correct
38 Correct 13 ms 16896 KB Output is correct