답안 #1046551

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046551 2024-08-06T16:34:33 Z sofijavelkovska 슈퍼트리 잇기 (IOI20_supertrees) C++17
65 / 100
112 ms 23364 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();
        while (!q.empty())
            q.pop();
        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 1;
            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:76:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (int j=0; j<subcomponents.size(); j++)
      |                       ~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:78:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             for (int t=0; t<subcomponents[j].size(); t++)
      |                           ~^~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:79:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |                 for (int k=t+1; k<subcomponents[j].size(); k++)
      |                                 ~^~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:83:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |                 for (int t=0; t<subcomponents.size(); t++)
      |                               ~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:94:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |             for (int j=0; j<component.size(); j++)
      |                           ~^~~~~~~~~~~~~~~~~
supertrees.cpp:95:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |                 for (int t=j+1; t<component.size(); t++)
      |                                 ~^~~~~~~~~~~~~~~~~
supertrees.cpp:99:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |         for (int j=0; j<subcomponents.size(); j++)
      |                       ~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:100:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |             for (int t=0; t<subcomponents[j].size()-1; t++)
      |                           ~^~~~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:116:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |         for (int j=0; j<subcomponents.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 348 KB Output is correct
6 Correct 4 ms 1284 KB Output is correct
7 Correct 97 ms 22100 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 4 ms 1284 KB Output is correct
7 Correct 97 ms 22100 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 1112 KB Output is correct
13 Correct 94 ms 22040 KB Output is correct
14 Incorrect 0 ms 348 KB WA in grader: construct returned 1 without calling build
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 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 1116 KB Output is correct
9 Correct 101 ms 22456 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 98 ms 22616 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 53 ms 13576 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 25 ms 6224 KB Output is correct
22 Correct 95 ms 23216 KB Output is correct
23 Correct 97 ms 23364 KB Output is correct
24 Correct 112 ms 23264 KB Output is correct
25 Correct 49 ms 13364 KB Output is correct
26 Correct 45 ms 13392 KB Output is correct
27 Correct 98 ms 23272 KB Output is correct
28 Correct 103 ms 23268 KB Output is correct
29 Correct 49 ms 13548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 24 ms 5860 KB Output is correct
5 Correct 95 ms 22012 KB Output is correct
6 Correct 101 ms 22100 KB Output is correct
7 Correct 101 ms 22100 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 24 ms 5836 KB Output is correct
10 Correct 94 ms 22100 KB Output is correct
11 Correct 104 ms 22008 KB Output is correct
12 Correct 100 ms 22104 KB Output is correct
13 Correct 1 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 24 ms 5784 KB Output is correct
17 Correct 111 ms 22088 KB Output is correct
18 Correct 98 ms 22036 KB Output is correct
19 Correct 93 ms 22100 KB Output is correct
20 Correct 99 ms 22356 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 4 ms 1284 KB Output is correct
7 Correct 97 ms 22100 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 1112 KB Output is correct
13 Correct 94 ms 22040 KB Output is correct
14 Incorrect 0 ms 348 KB WA in grader: construct returned 1 without calling build
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 348 KB Output is correct
6 Correct 4 ms 1284 KB Output is correct
7 Correct 97 ms 22100 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 1112 KB Output is correct
13 Correct 94 ms 22040 KB Output is correct
14 Incorrect 0 ms 348 KB WA in grader: construct returned 1 without calling build
15 Halted 0 ms 0 KB -