답안 #304810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304810 2020-09-21T22:54:53 Z azberjibiou 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
262 ms 26276 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sec second
#define pii pair<int, int>
#define pll pair<ll, ll>
const int mxN=1010;
using namespace std;
int N;
int Col1[mxN], Col2[mxN], idx1=1, idx2=1;
vector <int> col2s[mxN], col1s[mxN];
int tmp[mxN], idxt;
vector <int> P[mxN];
void dfs1(int num)
{
    for(int i=0;i<N;i++)
    {
        if(P[num][i]!=0 && Col1[i]==0)
        {
            Col1[i]=Col1[num];
            dfs1(i);
        }
    }
}
void dfs2(int col, int num)
{
    col2s[col].push_back(num);
    for(int i=0;i<N;i++)
    {
        if(P[num][i]==1 && Col2[i]==0)
        {
            Col2[i]=Col2[num];
            dfs2(col, i);
        }
    }
}
int construct(vector<vector<int>> p) {
	N = p.size();
	vector<vector<int>> ans;
	for (int i = 0; i < N; i++) {
		vector<int> row;
		row.resize(N);
		ans.push_back(row);
	}
	for(int i=0;i<N;i++)
    {
        P[i].resize(N);
        for(int j=0;j<N;j++)
        {
            P[i][j]=p[i][j];
        }
    }
	for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            if(P[i][j]==3)  return 0;
        }
    }
    for(int i=0;i<N;i++)
    {
        if(Col1[i]==0)
        {
            Col1[i]=idx1++;
            dfs1(i);
        }
    }
    for(int i=1;i<idx1;i++)
    {
        idxt=0;
        for(int j=0;j<N;j++)
        {
            if(Col1[j]==i)  tmp[idxt++]=j;
        }
        for(int j=0;j<idxt;j++)
        {
            for(int k=j+1;k<idxt;k++)
            {
                if(P[tmp[j]][tmp[k]]==0)  return 0;
            }
        }
    }
    for(int i=1;i<idx1;i++)
    {
        for(int j=0;j<N;j++)
        {
            if(Col1[j]==i && Col2[j]==0)
            {
                col1s[i].push_back(idx2);
                Col2[j]=idx2;
                dfs2(idx2, j);
                idx2++;
            }
        }
    }
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            if(Col2[i]==Col2[j])
            {
                if(P[i][j]!=1)  return 0;
            }
            else if(Col1[i]==Col1[j])
            {
                if(P[i][j]!=2)  return 0;
            }
            else
            {
                if(P[i][j]!=0)  return 0;
            }
        }
    }
    for(int i=1;i<idx2;i++)
    {
        if(col2s[i].empty())    continue;
        for(int j=0;j<col2s[i].size()-1;j++)
        {
            int now=col2s[i][j], nxt=col2s[i][j+1];
            ans[now][nxt]=1;
            ans[nxt][now]=1;
        }
    }
    for(int i=1;i<idx1;i++)
    {
        if(col1s[i].empty())    continue;
        if(col1s[i].size()==1)  continue;
        if(col1s[i].size()==2)  return 0;
        col1s[i].push_back(col1s[i][0]);
        for(int j=0;j<col1s[i].size()-1;j++)
        {
            int now=col2s[col1s[i][j]][0], nxt=col2s[col1s[i][j+1]][0];
            ans[now][nxt]=1;
            ans[nxt][now]=1;
        }
    }
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:118:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |         for(int j=0;j<col2s[i].size()-1;j++)
      |                     ~^~~~~~~~~~~~~~~~~~
supertrees.cpp:131:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |         for(int j=0;j<col1s[i].size()-1;j++)
      |                     ~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 259 ms 26104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 259 ms 26104 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 256 ms 26232 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 126 ms 16296 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 6904 KB Output is correct
21 Correct 253 ms 26104 KB Output is correct
22 Correct 252 ms 26104 KB Output is correct
23 Correct 257 ms 26104 KB Output is correct
24 Correct 242 ms 26108 KB Output is correct
25 Correct 110 ms 16164 KB Output is correct
26 Correct 107 ms 16120 KB Output is correct
27 Correct 261 ms 26276 KB Output is correct
28 Correct 242 ms 26108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 10 ms 1408 KB Output is correct
9 Correct 260 ms 26144 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 254 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 122 ms 16160 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 63 ms 6904 KB Output is correct
22 Correct 248 ms 26232 KB Output is correct
23 Correct 241 ms 26232 KB Output is correct
24 Correct 252 ms 26136 KB Output is correct
25 Correct 113 ms 16248 KB Output is correct
26 Correct 113 ms 16120 KB Output is correct
27 Correct 250 ms 26104 KB Output is correct
28 Correct 258 ms 26232 KB Output is correct
29 Correct 111 ms 16248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 61 ms 6904 KB Output is correct
5 Correct 256 ms 26104 KB Output is correct
6 Correct 246 ms 26104 KB Output is correct
7 Correct 262 ms 26104 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 63 ms 6904 KB Output is correct
10 Correct 247 ms 26232 KB Output is correct
11 Correct 238 ms 26104 KB Output is correct
12 Correct 254 ms 26232 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 61 ms 6904 KB Output is correct
17 Correct 243 ms 26104 KB Output is correct
18 Correct 246 ms 26232 KB Output is correct
19 Correct 251 ms 26104 KB Output is correct
20 Correct 246 ms 26232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 259 ms 26104 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 256 ms 26232 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 126 ms 16296 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 6904 KB Output is correct
21 Correct 253 ms 26104 KB Output is correct
22 Correct 252 ms 26104 KB Output is correct
23 Correct 257 ms 26104 KB Output is correct
24 Correct 242 ms 26108 KB Output is correct
25 Correct 110 ms 16164 KB Output is correct
26 Correct 107 ms 16120 KB Output is correct
27 Correct 261 ms 26276 KB Output is correct
28 Correct 242 ms 26108 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 260 ms 26144 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 254 ms 26104 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 6 ms 1024 KB Output is correct
45 Correct 122 ms 16160 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 63 ms 6904 KB Output is correct
50 Correct 248 ms 26232 KB Output is correct
51 Correct 241 ms 26232 KB Output is correct
52 Correct 252 ms 26136 KB Output is correct
53 Correct 113 ms 16248 KB Output is correct
54 Correct 113 ms 16120 KB Output is correct
55 Correct 250 ms 26104 KB Output is correct
56 Correct 258 ms 26232 KB Output is correct
57 Correct 111 ms 16248 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 6 ms 1024 KB Output is correct
61 Correct 124 ms 16164 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 512 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 63 ms 7032 KB Output is correct
66 Correct 111 ms 16120 KB Output is correct
67 Correct 114 ms 16124 KB Output is correct
68 Correct 107 ms 16120 KB Output is correct
69 Correct 112 ms 16248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 259 ms 26104 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 256 ms 26232 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 126 ms 16296 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 6904 KB Output is correct
21 Correct 253 ms 26104 KB Output is correct
22 Correct 252 ms 26104 KB Output is correct
23 Correct 257 ms 26104 KB Output is correct
24 Correct 242 ms 26108 KB Output is correct
25 Correct 110 ms 16164 KB Output is correct
26 Correct 107 ms 16120 KB Output is correct
27 Correct 261 ms 26276 KB Output is correct
28 Correct 242 ms 26108 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 260 ms 26144 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 254 ms 26104 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 6 ms 1024 KB Output is correct
45 Correct 122 ms 16160 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 63 ms 6904 KB Output is correct
50 Correct 248 ms 26232 KB Output is correct
51 Correct 241 ms 26232 KB Output is correct
52 Correct 252 ms 26136 KB Output is correct
53 Correct 113 ms 16248 KB Output is correct
54 Correct 113 ms 16120 KB Output is correct
55 Correct 250 ms 26104 KB Output is correct
56 Correct 258 ms 26232 KB Output is correct
57 Correct 111 ms 16248 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 61 ms 6904 KB Output is correct
62 Correct 256 ms 26104 KB Output is correct
63 Correct 246 ms 26104 KB Output is correct
64 Correct 262 ms 26104 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 63 ms 6904 KB Output is correct
67 Correct 247 ms 26232 KB Output is correct
68 Correct 238 ms 26104 KB Output is correct
69 Correct 254 ms 26232 KB Output is correct
70 Correct 0 ms 384 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 0 ms 384 KB Output is correct
73 Correct 61 ms 6904 KB Output is correct
74 Correct 243 ms 26104 KB Output is correct
75 Correct 246 ms 26232 KB Output is correct
76 Correct 251 ms 26104 KB Output is correct
77 Correct 246 ms 26232 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 0 ms 384 KB Output is correct
80 Correct 6 ms 1024 KB Output is correct
81 Correct 124 ms 16164 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 512 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 63 ms 7032 KB Output is correct
86 Correct 111 ms 16120 KB Output is correct
87 Correct 114 ms 16124 KB Output is correct
88 Correct 107 ms 16120 KB Output is correct
89 Correct 112 ms 16248 KB Output is correct
90 Correct 0 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 7 ms 1024 KB Output is correct
93 Correct 116 ms 16120 KB Output is correct
94 Correct 0 ms 384 KB Output is correct
95 Correct 0 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 27 ms 4344 KB Output is correct
98 Correct 107 ms 16164 KB Output is correct
99 Correct 115 ms 16120 KB Output is correct
100 Correct 105 ms 16124 KB Output is correct
101 Correct 105 ms 16164 KB Output is correct
102 Correct 116 ms 16160 KB Output is correct
103 Correct 115 ms 16120 KB Output is correct
104 Correct 121 ms 16168 KB Output is correct
105 Correct 116 ms 16376 KB Output is correct