답안 #1046556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046556 2024-08-06T16:48:28 Z sofijavelkovska 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
126 ms 22612 KB
#include "supertrees.h"
//#include "grader.cpp"

#include <bits/stdc++.h>
using namespace std;

int construct(vector<vector<int> > adj)
{
	int n=adj.size();
	vector<vector<int> > answer;
	for (int i=0; i<n; i++)
    {
        vector<int> row;
        row.resize(n, 0);
        answer.push_back(row);
    }
    for (int i=0; i<n; i++)
        for (int j=i+1; j<n; j++)
            if (adj[i][j]==3)
                return 0;
	int visited[n]={0};
	queue<int> q;
	vector<int> component;
	vector<vector<int> > subcomponents;
	for (int i=0; i<n; i++)
    {
        if (visited[i])
            continue;
        visited[i]=1;
        q.push(i);
        component.clear();
        while (!q.empty())
        {
            int x=q.front();
            q.pop();
            component.push_back(x);
            for (int j=0; j<n; j++)
                if (adj[x][j]>0 && !visited[j])
                {
                    visited[j]=1;
                    q.push(j);
                }
        }
        subcomponents.clear();
        for (auto x : component)
        {
            if (visited[x]==2)
                continue;
            visited[x]=2;
            q.push(x);
            vector<int> newcomp;
            subcomponents.push_back(newcomp);
            while (!q.empty())
            {
                int y=q.front();
                q.pop();
                subcomponents.back().push_back(y);
                for (auto z : component)
                    if (y!=z && adj[y][z]==1 && visited[z]!=2)
                    {
                        visited[z]=2;
                        q.push(z);
                    }
            }
        }
        /*for (auto c : subcomponents)
        {
            cout << "subc ";
            for (auto x : c)
                cout << x << ' ';
            cout << '\n';
        }
        cout << "end\n";*/
        for (int j=0; j<subcomponents.size(); j++)
        {
            for (int t=0; t<subcomponents[j].size(); t++)
                for (int k=t+1; k<subcomponents[j].size(); k++)
                    if (adj[subcomponents[j][t]][subcomponents[j][k]]!=1)
                        return 0;
            for (auto x : subcomponents[j])
                for (int t=0; t<subcomponents.size(); t++)
                {
                    if (t==j)
                        continue;
                    for (auto y : subcomponents[t])
                        if (adj[x][y]!=2)
                            return 0;
                }
        }
        if (subcomponents.size()==2)
        {
            for (int j=0; j<component.size(); j++)
                for (int t=j+1; t<component.size(); t++)
                    if (adj[j][t]!=1)
                        return 0;
        }
        for (int j=0; j<subcomponents.size(); j++)
            for (int t=0; t<subcomponents[j].size()-1; t++)
            {
                int x=subcomponents[j][t];
                int y=subcomponents[j][t+1];
                answer[x][y]=1;
                answer[y][x]=1;
            }
        if (subcomponents.size()==1)
            continue;
        if (subcomponents.size()==2)
        {
            int x=subcomponents[0][0];
            int y=subcomponents[1][0];
            answer[x][y]=1;
            answer[y][x]=1;
        }
        for (int j=0; j<subcomponents.size(); j++)
        {
            int x=subcomponents[j][0];
            int y=subcomponents[(j+1)%subcomponents.size()][0];
            answer[x][y]=1;
            answer[y][x]=1;
        }
    }
	build(answer);

	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:17:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   17 |     for (int i=0; i<n; i++)
      |     ^~~
supertrees.cpp:21:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   21 |  int visited[n]={0};
      |  ^~~
supertrees.cpp:74:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for (int j=0; j<subcomponents.size(); j++)
      |                       ~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:76:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             for (int t=0; t<subcomponents[j].size(); t++)
      |                           ~^~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:77:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |                 for (int k=t+1; k<subcomponents[j].size(); k++)
      |                                 ~^~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:81:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                 for (int t=0; t<subcomponents.size(); t++)
      |                               ~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:92:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |             for (int j=0; j<component.size(); j++)
      |                           ~^~~~~~~~~~~~~~~~~
supertrees.cpp:93:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |                 for (int t=j+1; t<component.size(); t++)
      |                                 ~^~~~~~~~~~~~~~~~~
supertrees.cpp:97:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |         for (int j=0; j<subcomponents.size(); j++)
      |                       ~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:98:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |             for (int t=0; t<subcomponents[j].size()-1; t++)
      |                           ~^~~~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:114:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |         for (int j=0; j<subcomponents.size(); j++)
      |                       ~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 4 ms 1116 KB Output is correct
7 Correct 95 ms 22064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 4 ms 1116 KB Output is correct
7 Correct 95 ms 22064 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 4 ms 1116 KB Output is correct
13 Correct 126 ms 22148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 58 ms 12548 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 5776 KB Output is correct
21 Correct 102 ms 22492 KB Output is correct
22 Correct 97 ms 22608 KB Output is correct
23 Correct 101 ms 22608 KB Output is correct
24 Correct 96 ms 22608 KB Output is correct
25 Correct 44 ms 12624 KB Output is correct
26 Correct 42 ms 12552 KB Output is correct
27 Correct 115 ms 22556 KB Output is correct
28 Correct 102 ms 22608 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 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 4 ms 1268 KB Output is correct
9 Correct 95 ms 22112 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 97 ms 22036 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 59 ms 12292 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 344 KB Output is correct
21 Correct 24 ms 5724 KB Output is correct
22 Correct 122 ms 22096 KB Output is correct
23 Correct 95 ms 22096 KB Output is correct
24 Correct 112 ms 22176 KB Output is correct
25 Correct 44 ms 12116 KB Output is correct
26 Correct 43 ms 12120 KB Output is correct
27 Correct 111 ms 22036 KB Output is correct
28 Correct 109 ms 22612 KB Output is correct
29 Correct 44 ms 12116 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 24 ms 5728 KB Output is correct
5 Correct 105 ms 22104 KB Output is correct
6 Correct 115 ms 21952 KB Output is correct
7 Correct 101 ms 22096 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 24 ms 5720 KB Output is correct
10 Correct 100 ms 22100 KB Output is correct
11 Correct 94 ms 22104 KB Output is correct
12 Correct 101 ms 22032 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 28 ms 5724 KB Output is correct
17 Correct 98 ms 22100 KB Output is correct
18 Correct 97 ms 22096 KB Output is correct
19 Correct 96 ms 22188 KB Output is correct
20 Correct 102 ms 22096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 4 ms 1116 KB Output is correct
7 Correct 95 ms 22064 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 4 ms 1116 KB Output is correct
13 Correct 126 ms 22148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 58 ms 12548 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 5776 KB Output is correct
21 Correct 102 ms 22492 KB Output is correct
22 Correct 97 ms 22608 KB Output is correct
23 Correct 101 ms 22608 KB Output is correct
24 Correct 96 ms 22608 KB Output is correct
25 Correct 44 ms 12624 KB Output is correct
26 Correct 42 ms 12552 KB Output is correct
27 Correct 115 ms 22556 KB Output is correct
28 Correct 102 ms 22608 KB Output is correct
29 Correct 0 ms 344 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 4 ms 1268 KB Output is correct
37 Correct 95 ms 22112 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1116 KB Output is correct
41 Correct 97 ms 22036 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 59 ms 12292 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 344 KB Output is correct
49 Correct 24 ms 5724 KB Output is correct
50 Correct 122 ms 22096 KB Output is correct
51 Correct 95 ms 22096 KB Output is correct
52 Correct 112 ms 22176 KB Output is correct
53 Correct 44 ms 12116 KB Output is correct
54 Correct 43 ms 12120 KB Output is correct
55 Correct 111 ms 22036 KB Output is correct
56 Correct 109 ms 22612 KB Output is correct
57 Correct 44 ms 12116 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 2 ms 860 KB Output is correct
61 Correct 62 ms 13432 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 24 ms 6232 KB Output is correct
66 Correct 53 ms 13500 KB Output is correct
67 Correct 48 ms 13372 KB Output is correct
68 Correct 43 ms 13540 KB Output is correct
69 Correct 43 ms 13396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 4 ms 1116 KB Output is correct
7 Correct 95 ms 22064 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 4 ms 1116 KB Output is correct
13 Correct 126 ms 22148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 58 ms 12548 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 5776 KB Output is correct
21 Correct 102 ms 22492 KB Output is correct
22 Correct 97 ms 22608 KB Output is correct
23 Correct 101 ms 22608 KB Output is correct
24 Correct 96 ms 22608 KB Output is correct
25 Correct 44 ms 12624 KB Output is correct
26 Correct 42 ms 12552 KB Output is correct
27 Correct 115 ms 22556 KB Output is correct
28 Correct 102 ms 22608 KB Output is correct
29 Correct 0 ms 344 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 4 ms 1268 KB Output is correct
37 Correct 95 ms 22112 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1116 KB Output is correct
41 Correct 97 ms 22036 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 59 ms 12292 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 344 KB Output is correct
49 Correct 24 ms 5724 KB Output is correct
50 Correct 122 ms 22096 KB Output is correct
51 Correct 95 ms 22096 KB Output is correct
52 Correct 112 ms 22176 KB Output is correct
53 Correct 44 ms 12116 KB Output is correct
54 Correct 43 ms 12120 KB Output is correct
55 Correct 111 ms 22036 KB Output is correct
56 Correct 109 ms 22612 KB Output is correct
57 Correct 44 ms 12116 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 24 ms 5728 KB Output is correct
62 Correct 105 ms 22104 KB Output is correct
63 Correct 115 ms 21952 KB Output is correct
64 Correct 101 ms 22096 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 24 ms 5720 KB Output is correct
67 Correct 100 ms 22100 KB Output is correct
68 Correct 94 ms 22104 KB Output is correct
69 Correct 101 ms 22032 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 28 ms 5724 KB Output is correct
74 Correct 98 ms 22100 KB Output is correct
75 Correct 97 ms 22096 KB Output is correct
76 Correct 96 ms 22188 KB Output is correct
77 Correct 102 ms 22096 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 2 ms 860 KB Output is correct
81 Correct 62 ms 13432 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 24 ms 6232 KB Output is correct
86 Correct 53 ms 13500 KB Output is correct
87 Correct 48 ms 13372 KB Output is correct
88 Correct 43 ms 13540 KB Output is correct
89 Correct 43 ms 13396 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 2 ms 860 KB Output is correct
93 Correct 44 ms 13452 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 11 ms 3844 KB Output is correct
98 Correct 88 ms 13552 KB Output is correct
99 Correct 45 ms 13532 KB Output is correct
100 Correct 42 ms 13396 KB Output is correct
101 Correct 42 ms 13324 KB Output is correct
102 Correct 41 ms 13304 KB Output is correct
103 Correct 44 ms 13608 KB Output is correct
104 Correct 40 ms 12036 KB Output is correct
105 Correct 52 ms 12116 KB Output is correct