답안 #521251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521251 2022-02-01T09:59:37 Z oneloveforever 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
224 ms 24108 KB
#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define ll long long
struct DSU
{
    int n;
    vector<int>trace;
    DSU(int _n=0)
    {
        n=_n;
        trace.resize(n+7);
        iota(trace.begin(),trace.end(),0);
    }
    int get(int x)
    {
        return trace[x]==x?trace[x]:trace[x]=get(trace[x]);
    }
    void connect(int x,int y)
    {
        int u=get(x);
        int v=get(y);
        if(u==v)return ;
        trace[v]=u;
    }
};
int construct(vector<vector<int> >p)
{
    int n=p.size();
    DSU only(n);
    DSU can(n);
    for(int i=0;i<=n-1;i++)
    {
        for(int j=0;j<=n-1;j++)if(p[i][j]==3)return 0;
    }
    vector<vector<int> >b(n,vector<int>(n));
    for(int i=0;i<=n-1;i++)
    {
        for(int j=i+1;j<=n-1;j++)
        {
            if(p[i][j]==1)only.connect(i,j);
            if(p[i][j])can.connect(i,j);
        }
    }
    for(int i=0;i<=n-1;i++)
    {
        if(can.get(i)!=i)continue;
        vector<int>q;
        for(int node=0;node<=n-1;node++)
        {
            if(can.get(node)==i&&only.get(node)==node)q.push_back(node);
        }
        if((int)q.size()==1)continue;
        if((int)q.size()==2)return 0;
        for(int node=0;node<=q.size()-1;node++)
        {
            int node_x=q[node];
            int node_y=q[(node+1)%(int)q.size()];
            b[node_x][node_y]=1;
            b[node_y][node_x]=1;
        }
    }
    for(int i=0;i<=n-1;i++)if(only.get(i)!=i)
    {
        int node=only.get(i);
        b[node][i]=b[i][node]=1;
    }
    for(int i=0;i<=n-1;i++)
    {
        for(int j=i+1;j<=n-1;j++)
        {
            if(only.get(i)==only.get(j))
            {
                //cout<<i<<" "<<j<<" "<<p[i][j]<<endl;
                if(p[i][j]!=1)return false;
            }
            else if(can.get(i)==can.get(j))
            {
                if(p[i][j]!=2)return false;
            }
            else
            {
                if(p[i][j])return false;
            }
        }
    }
    build(b);
    return 1;


}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:55:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int node=0;node<=q.size()-1;node++)
      |                        ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 193 ms 22400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 193 ms 22400 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1228 KB Output is correct
13 Correct 186 ms 22140 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 83 ms 12164 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 47 ms 5948 KB Output is correct
21 Correct 192 ms 22268 KB Output is correct
22 Correct 185 ms 22104 KB Output is correct
23 Correct 204 ms 22264 KB Output is correct
24 Correct 182 ms 22220 KB Output is correct
25 Correct 74 ms 12228 KB Output is correct
26 Correct 79 ms 12268 KB Output is correct
27 Correct 201 ms 22272 KB Output is correct
28 Correct 182 ms 22284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 272 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 8 ms 1188 KB Output is correct
9 Correct 190 ms 24000 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1228 KB Output is correct
13 Correct 186 ms 23992 KB Output is correct
14 Correct 0 ms 296 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 95 ms 14064 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 46 ms 6252 KB Output is correct
22 Correct 188 ms 24044 KB Output is correct
23 Correct 194 ms 24004 KB Output is correct
24 Correct 224 ms 23968 KB Output is correct
25 Correct 77 ms 13988 KB Output is correct
26 Correct 77 ms 14072 KB Output is correct
27 Correct 188 ms 23928 KB Output is correct
28 Correct 193 ms 24004 KB Output is correct
29 Correct 91 ms 14020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 47 ms 6252 KB Output is correct
5 Correct 182 ms 24004 KB Output is correct
6 Correct 180 ms 23912 KB Output is correct
7 Correct 193 ms 24004 KB Output is correct
8 Correct 1 ms 216 KB Output is correct
9 Correct 47 ms 6256 KB Output is correct
10 Correct 201 ms 23944 KB Output is correct
11 Correct 207 ms 23972 KB Output is correct
12 Correct 212 ms 23912 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 47 ms 6184 KB Output is correct
17 Correct 204 ms 23968 KB Output is correct
18 Correct 202 ms 24108 KB Output is correct
19 Correct 184 ms 23924 KB Output is correct
20 Correct 183 ms 23880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 193 ms 22400 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1228 KB Output is correct
13 Correct 186 ms 22140 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 83 ms 12164 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 47 ms 5948 KB Output is correct
21 Correct 192 ms 22268 KB Output is correct
22 Correct 185 ms 22104 KB Output is correct
23 Correct 204 ms 22264 KB Output is correct
24 Correct 182 ms 22220 KB Output is correct
25 Correct 74 ms 12228 KB Output is correct
26 Correct 79 ms 12268 KB Output is correct
27 Correct 201 ms 22272 KB Output is correct
28 Correct 182 ms 22284 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 272 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 8 ms 1188 KB Output is correct
37 Correct 190 ms 24000 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 8 ms 1228 KB Output is correct
41 Correct 186 ms 23992 KB Output is correct
42 Correct 0 ms 296 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 4 ms 844 KB Output is correct
45 Correct 95 ms 14064 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 46 ms 6252 KB Output is correct
50 Correct 188 ms 24044 KB Output is correct
51 Correct 194 ms 24004 KB Output is correct
52 Correct 224 ms 23968 KB Output is correct
53 Correct 77 ms 13988 KB Output is correct
54 Correct 77 ms 14072 KB Output is correct
55 Correct 188 ms 23928 KB Output is correct
56 Correct 193 ms 24004 KB Output is correct
57 Correct 91 ms 14020 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 4 ms 844 KB Output is correct
61 Correct 96 ms 14056 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 0 ms 288 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 47 ms 6232 KB Output is correct
66 Correct 76 ms 14024 KB Output is correct
67 Correct 89 ms 14056 KB Output is correct
68 Correct 74 ms 13984 KB Output is correct
69 Correct 72 ms 14060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 193 ms 22400 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1228 KB Output is correct
13 Correct 186 ms 22140 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 83 ms 12164 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 47 ms 5948 KB Output is correct
21 Correct 192 ms 22268 KB Output is correct
22 Correct 185 ms 22104 KB Output is correct
23 Correct 204 ms 22264 KB Output is correct
24 Correct 182 ms 22220 KB Output is correct
25 Correct 74 ms 12228 KB Output is correct
26 Correct 79 ms 12268 KB Output is correct
27 Correct 201 ms 22272 KB Output is correct
28 Correct 182 ms 22284 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 272 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 8 ms 1188 KB Output is correct
37 Correct 190 ms 24000 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 8 ms 1228 KB Output is correct
41 Correct 186 ms 23992 KB Output is correct
42 Correct 0 ms 296 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 4 ms 844 KB Output is correct
45 Correct 95 ms 14064 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 46 ms 6252 KB Output is correct
50 Correct 188 ms 24044 KB Output is correct
51 Correct 194 ms 24004 KB Output is correct
52 Correct 224 ms 23968 KB Output is correct
53 Correct 77 ms 13988 KB Output is correct
54 Correct 77 ms 14072 KB Output is correct
55 Correct 188 ms 23928 KB Output is correct
56 Correct 193 ms 24004 KB Output is correct
57 Correct 91 ms 14020 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 47 ms 6252 KB Output is correct
62 Correct 182 ms 24004 KB Output is correct
63 Correct 180 ms 23912 KB Output is correct
64 Correct 193 ms 24004 KB Output is correct
65 Correct 1 ms 216 KB Output is correct
66 Correct 47 ms 6256 KB Output is correct
67 Correct 201 ms 23944 KB Output is correct
68 Correct 207 ms 23972 KB Output is correct
69 Correct 212 ms 23912 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 47 ms 6184 KB Output is correct
74 Correct 204 ms 23968 KB Output is correct
75 Correct 202 ms 24108 KB Output is correct
76 Correct 184 ms 23924 KB Output is correct
77 Correct 183 ms 23880 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 4 ms 844 KB Output is correct
81 Correct 96 ms 14056 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 0 ms 288 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 47 ms 6232 KB Output is correct
86 Correct 76 ms 14024 KB Output is correct
87 Correct 89 ms 14056 KB Output is correct
88 Correct 74 ms 13984 KB Output is correct
89 Correct 72 ms 14060 KB Output is correct
90 Correct 0 ms 288 KB Output is correct
91 Correct 0 ms 204 KB Output is correct
92 Correct 4 ms 664 KB Output is correct
93 Correct 76 ms 10088 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 0 ms 296 KB Output is correct
97 Correct 24 ms 2656 KB Output is correct
98 Correct 84 ms 10100 KB Output is correct
99 Correct 74 ms 10100 KB Output is correct
100 Correct 70 ms 10088 KB Output is correct
101 Correct 72 ms 10092 KB Output is correct
102 Correct 87 ms 10088 KB Output is correct
103 Correct 92 ms 10108 KB Output is correct
104 Correct 79 ms 10092 KB Output is correct
105 Correct 78 ms 10052 KB Output is correct