답안 #800215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800215 2023-08-01T12:08:09 Z I_Love_EliskaM_ 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
178 ms 24064 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second
using ll = long long;

struct DSU {
    vector<int> p,sz;
    DSU(int n) {
        forn(i,n) p.pb(i), sz.pb(1);
    }
    int get(int u) {
        return p[u]==u?u:get(p[u]);
    }
    void uni(int u, int v) {
        u=get(u), v=get(v);
        if (u==v) return;
        if (sz[u]<sz[v]) swap(u,v);
        sz[u]+=sz[v];
        p[v]=u;
    }
};

int construct(vector<vector<int>> p) {
    int n=p.size();
    DSU dsu(n);
    forn(i,n) forn(j,n) if (p[i][j]) dsu.uni(i,j);
    vector<vector<int>> v(n);
    forn(i,n) v[dsu.get(i)].pb(i);

    vector<vector<int>> ans(n,vector<int>(n,0));

    forn(i,n) {
        if (!v[i].size()) continue;
        if (v[i].size()==1) continue;
        DSU dsu2(n);
        for(auto&x:v[i]) {
            for(auto&y:v[i]) {
                if (p[x][y]==1) dsu2.uni(x,y);
                if (p[x][y]==0) return 0;
            }
        }
        for(auto&x:v[i]) {
            for(auto&y:v[i]) {
                if (dsu2.get(x)==dsu2.get(y)) {
                    if (p[x][y]!=1) return 0;
                }
            }
        }
        vector<vector<int>> u(n);
        for(auto&x:v[i]) u[dsu2.get(x)].pb(x);

        forn(j,n) {
            if (!u[j].size()) continue;
            if (u[j].size()==1) continue;
            forn(k,u[j].size()-1) ans[u[j][k]][u[j][k+1]]=ans[u[j][k+1]][u[j][k]]=1;
        }

        vector<int> two;
        for(auto&x:v[i]) {
            if (x!=u[dsu2.get(x)].back()) continue;
            int z=3;
            for(auto&y:v[i]) {
                if (dsu2.get(x)==dsu2.get(y)) continue;
                if (p[x][y]!=2) return 0;
                z&=p[x][y]==2;
            }
            if (z==1) two.pb(x);
        }
        //assert(two.size()>=3 || two.size()==0);
        if (two.size()>0 && two.size()<3) return 0;
        forn(j,two.size()) {
            ans[two[j]][two[(j+1)%two.size()]]=ans[two[(j+1)%two.size()]][two[j]]=1;
        }
    }

    //forn(i,n) {
    //    forn(j,n) cout<<ans[i][j]<<' '; cout<<'\n';
    //}
    build(ans);

    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for(int i=0;i<n;++i)
......
   61 |             forn(k,u[j].size()-1) ans[u[j][k]][u[j][k+1]]=ans[u[j][k+1]][u[j][k]]=1;
      |                  ~~~~~~~~~~~~~~~
supertrees.cpp:61:13: note: in expansion of macro 'forn'
   61 |             forn(k,u[j].size()-1) ans[u[j][k]][u[j][k+1]]=ans[u[j][k+1]][u[j][k]]=1;
      |             ^~~~
supertrees.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for(int i=0;i<n;++i)
......
   77 |         forn(j,two.size()) {
      |              ~~~~~~~~~~~~       
supertrees.cpp:77:9: note: in expansion of macro 'forn'
   77 |         forn(j,two.size()) {
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 170 ms 24016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 170 ms 24016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 158 ms 24044 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 14084 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 6188 KB Output is correct
21 Correct 163 ms 24056 KB Output is correct
22 Correct 162 ms 24012 KB Output is correct
23 Correct 170 ms 23980 KB Output is correct
24 Correct 159 ms 24052 KB Output is correct
25 Correct 61 ms 14080 KB Output is correct
26 Correct 61 ms 14072 KB Output is correct
27 Correct 166 ms 23932 KB Output is correct
28 Correct 163 ms 24020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 165 ms 23992 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1252 KB Output is correct
13 Correct 164 ms 24020 KB Output is correct
14 Correct 0 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 73 ms 14064 KB Output is correct
18 Correct 0 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 40 ms 6180 KB Output is correct
22 Correct 158 ms 24012 KB Output is correct
23 Correct 158 ms 23984 KB Output is correct
24 Correct 166 ms 23980 KB Output is correct
25 Correct 61 ms 14068 KB Output is correct
26 Correct 61 ms 14080 KB Output is correct
27 Correct 178 ms 24000 KB Output is correct
28 Correct 166 ms 23964 KB Output is correct
29 Correct 65 ms 14204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 40 ms 6192 KB Output is correct
5 Correct 160 ms 24052 KB Output is correct
6 Correct 178 ms 24032 KB Output is correct
7 Correct 168 ms 24008 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 41 ms 6276 KB Output is correct
10 Correct 161 ms 24052 KB Output is correct
11 Correct 165 ms 24024 KB Output is correct
12 Correct 172 ms 24012 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 41 ms 6260 KB Output is correct
17 Correct 160 ms 24056 KB Output is correct
18 Correct 164 ms 23936 KB Output is correct
19 Correct 160 ms 24024 KB Output is correct
20 Correct 158 ms 24064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 170 ms 24016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 158 ms 24044 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 14084 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 6188 KB Output is correct
21 Correct 163 ms 24056 KB Output is correct
22 Correct 162 ms 24012 KB Output is correct
23 Correct 170 ms 23980 KB Output is correct
24 Correct 159 ms 24052 KB Output is correct
25 Correct 61 ms 14080 KB Output is correct
26 Correct 61 ms 14072 KB Output is correct
27 Correct 166 ms 23932 KB Output is correct
28 Correct 163 ms 24020 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 296 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 304 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 165 ms 23992 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1252 KB Output is correct
41 Correct 164 ms 24020 KB Output is correct
42 Correct 0 ms 300 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 73 ms 14064 KB Output is correct
46 Correct 0 ms 300 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 40 ms 6180 KB Output is correct
50 Correct 158 ms 24012 KB Output is correct
51 Correct 158 ms 23984 KB Output is correct
52 Correct 166 ms 23980 KB Output is correct
53 Correct 61 ms 14068 KB Output is correct
54 Correct 61 ms 14080 KB Output is correct
55 Correct 178 ms 24000 KB Output is correct
56 Correct 166 ms 23964 KB Output is correct
57 Correct 65 ms 14204 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 852 KB Output is correct
61 Correct 67 ms 14028 KB Output is correct
62 Correct 0 ms 300 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 304 KB Output is correct
65 Correct 40 ms 6220 KB Output is correct
66 Correct 62 ms 14084 KB Output is correct
67 Correct 61 ms 14076 KB Output is correct
68 Correct 60 ms 14072 KB Output is correct
69 Correct 60 ms 14192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 170 ms 24016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 158 ms 24044 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 14084 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 6188 KB Output is correct
21 Correct 163 ms 24056 KB Output is correct
22 Correct 162 ms 24012 KB Output is correct
23 Correct 170 ms 23980 KB Output is correct
24 Correct 159 ms 24052 KB Output is correct
25 Correct 61 ms 14080 KB Output is correct
26 Correct 61 ms 14072 KB Output is correct
27 Correct 166 ms 23932 KB Output is correct
28 Correct 163 ms 24020 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 296 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 304 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 165 ms 23992 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1252 KB Output is correct
41 Correct 164 ms 24020 KB Output is correct
42 Correct 0 ms 300 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 73 ms 14064 KB Output is correct
46 Correct 0 ms 300 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 40 ms 6180 KB Output is correct
50 Correct 158 ms 24012 KB Output is correct
51 Correct 158 ms 23984 KB Output is correct
52 Correct 166 ms 23980 KB Output is correct
53 Correct 61 ms 14068 KB Output is correct
54 Correct 61 ms 14080 KB Output is correct
55 Correct 178 ms 24000 KB Output is correct
56 Correct 166 ms 23964 KB Output is correct
57 Correct 65 ms 14204 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 40 ms 6192 KB Output is correct
62 Correct 160 ms 24052 KB Output is correct
63 Correct 178 ms 24032 KB Output is correct
64 Correct 168 ms 24008 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 41 ms 6276 KB Output is correct
67 Correct 161 ms 24052 KB Output is correct
68 Correct 165 ms 24024 KB Output is correct
69 Correct 172 ms 24012 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 41 ms 6260 KB Output is correct
74 Correct 160 ms 24056 KB Output is correct
75 Correct 164 ms 23936 KB Output is correct
76 Correct 160 ms 24024 KB Output is correct
77 Correct 158 ms 24064 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 3 ms 852 KB Output is correct
81 Correct 67 ms 14028 KB Output is correct
82 Correct 0 ms 300 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 304 KB Output is correct
85 Correct 40 ms 6220 KB Output is correct
86 Correct 62 ms 14084 KB Output is correct
87 Correct 61 ms 14076 KB Output is correct
88 Correct 60 ms 14072 KB Output is correct
89 Correct 60 ms 14192 KB Output is correct
90 Correct 0 ms 296 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 852 KB Output is correct
93 Correct 66 ms 14128 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 16 ms 3700 KB Output is correct
98 Correct 66 ms 14252 KB Output is correct
99 Correct 62 ms 14116 KB Output is correct
100 Correct 61 ms 14064 KB Output is correct
101 Correct 65 ms 14120 KB Output is correct
102 Correct 64 ms 14156 KB Output is correct
103 Correct 63 ms 14156 KB Output is correct
104 Correct 68 ms 14076 KB Output is correct
105 Correct 68 ms 14080 KB Output is correct