답안 #864748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864748 2023-10-23T14:14:16 Z andrei_boaca 슈퍼트리 잇기 (IOI20_supertrees) C++17
40 / 100
172 ms 32292 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;

int n;
vector<vector<int>> adj;
vector<int> muchii[1005];
int comp[1005],nrcomp;
vector<int> nodes;
void dfs(int nod)
{
    comp[nod]=nrcomp;
    nodes.push_back(nod);
    for(int i:muchii[nod])
        if(!comp[i])
            dfs(i);
}
int construct(std::vector<std::vector<int>> p)
{
    n=p.size();
    adj.resize(n);
    for(int i=0;i<n;i++)
        adj[i].resize(n);
    bool sub1=1;
    bool sub2=1;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            sub1&=(p[i][j]<=1);
            sub2&=(p[i][j]==0||p[i][j]==2||i==j);
        }
    if(sub1||sub2)
    {
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            {
                if(sub1)
                {
                    if(p[i][j]==1)
                    {
                        muchii[i].push_back(j);
                        muchii[j].push_back(i);
                    }
                }
                else
                {
                    if(p[i][j]==2)
                    {
                        muchii[i].push_back(j);
                        muchii[j].push_back(i);
                    }
                }
            }
        for(int i=0;i<n;i++)
            if(comp[i]==0)
            {
                nrcomp++;
                nodes.clear();
                dfs(i);
                for(int j=1;j<nodes.size();j++)
                {
                    int a=nodes[j-1];
                    int b=nodes[j];
                    adj[a][b]=adj[b][a]=1;
                }
                if(sub2&&nodes.size()==2)
                    return 0;
                if(sub2)
                {
                    int a=nodes[0];
                    int b=nodes.back();
                    if(a!=b)
                    {
                        adj[a][b]=1;
                        adj[b][a]=1;
                    }
                }
            }
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            {
                if(p[i][j]==0&&comp[i]==comp[j])
                    return 0;
                if(p[i][j]>0&&comp[i]!=comp[j])
                    return 0;
            }
        build(adj);
        return 1;
    }
	return 0;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:62:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                 for(int j=1;j<nodes.size();j++)
      |                             ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 152 ms 30248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 152 ms 30248 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 143 ms 22112 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 1128 KB Output is correct
17 Correct 71 ms 17960 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 43 ms 6256 KB Output is correct
21 Correct 172 ms 23120 KB Output is correct
22 Correct 141 ms 22052 KB Output is correct
23 Correct 154 ms 26196 KB Output is correct
24 Correct 144 ms 22052 KB Output is correct
25 Correct 64 ms 13364 KB Output is correct
26 Correct 58 ms 12116 KB Output is correct
27 Correct 155 ms 28208 KB Output is correct
28 Correct 145 ms 22044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 6 ms 1372 KB Output is correct
9 Correct 146 ms 24152 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1628 KB Output is correct
13 Correct 154 ms 32292 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1240 KB Output is correct
17 Correct 73 ms 19796 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 42 ms 6484 KB Output is correct
22 Correct 148 ms 25108 KB Output is correct
23 Correct 147 ms 24004 KB Output is correct
24 Correct 156 ms 30288 KB Output is correct
25 Correct 59 ms 14116 KB Output is correct
26 Correct 63 ms 15184 KB Output is correct
27 Correct 155 ms 24088 KB Output is correct
28 Correct 155 ms 28196 KB Output is correct
29 Correct 59 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 38 ms 5944 KB Output is correct
5 Correct 146 ms 23180 KB Output is correct
6 Correct 152 ms 22052 KB Output is correct
7 Correct 153 ms 26204 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 39 ms 6228 KB Output is correct
10 Correct 160 ms 23304 KB Output is correct
11 Correct 170 ms 22060 KB Output is correct
12 Correct 165 ms 28192 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 152 ms 30248 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 143 ms 22112 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 1128 KB Output is correct
17 Correct 71 ms 17960 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 43 ms 6256 KB Output is correct
21 Correct 172 ms 23120 KB Output is correct
22 Correct 141 ms 22052 KB Output is correct
23 Correct 154 ms 26196 KB Output is correct
24 Correct 144 ms 22052 KB Output is correct
25 Correct 64 ms 13364 KB Output is correct
26 Correct 58 ms 12116 KB Output is correct
27 Correct 155 ms 28208 KB Output is correct
28 Correct 145 ms 22044 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 6 ms 1372 KB Output is correct
37 Correct 146 ms 24152 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 7 ms 1628 KB Output is correct
41 Correct 154 ms 32292 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 4 ms 1240 KB Output is correct
45 Correct 73 ms 19796 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 42 ms 6484 KB Output is correct
50 Correct 148 ms 25108 KB Output is correct
51 Correct 147 ms 24004 KB Output is correct
52 Correct 156 ms 30288 KB Output is correct
53 Correct 59 ms 14116 KB Output is correct
54 Correct 63 ms 15184 KB Output is correct
55 Correct 155 ms 24088 KB Output is correct
56 Correct 155 ms 28196 KB Output is correct
57 Correct 59 ms 14160 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 924 KB Output is correct
61 Correct 79 ms 14096 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
64 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 152 ms 30248 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 143 ms 22112 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 1128 KB Output is correct
17 Correct 71 ms 17960 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 43 ms 6256 KB Output is correct
21 Correct 172 ms 23120 KB Output is correct
22 Correct 141 ms 22052 KB Output is correct
23 Correct 154 ms 26196 KB Output is correct
24 Correct 144 ms 22052 KB Output is correct
25 Correct 64 ms 13364 KB Output is correct
26 Correct 58 ms 12116 KB Output is correct
27 Correct 155 ms 28208 KB Output is correct
28 Correct 145 ms 22044 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 6 ms 1372 KB Output is correct
37 Correct 146 ms 24152 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 7 ms 1628 KB Output is correct
41 Correct 154 ms 32292 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 4 ms 1240 KB Output is correct
45 Correct 73 ms 19796 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 42 ms 6484 KB Output is correct
50 Correct 148 ms 25108 KB Output is correct
51 Correct 147 ms 24004 KB Output is correct
52 Correct 156 ms 30288 KB Output is correct
53 Correct 59 ms 14116 KB Output is correct
54 Correct 63 ms 15184 KB Output is correct
55 Correct 155 ms 24088 KB Output is correct
56 Correct 155 ms 28196 KB Output is correct
57 Correct 59 ms 14160 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 38 ms 5944 KB Output is correct
62 Correct 146 ms 23180 KB Output is correct
63 Correct 152 ms 22052 KB Output is correct
64 Correct 153 ms 26204 KB Output is correct
65 Correct 0 ms 600 KB Output is correct
66 Correct 39 ms 6228 KB Output is correct
67 Correct 160 ms 23304 KB Output is correct
68 Correct 170 ms 22060 KB Output is correct
69 Correct 165 ms 28192 KB Output is correct
70 Correct 1 ms 596 KB Output is correct
71 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
72 Halted 0 ms 0 KB -