답안 #440280

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440280 2021-07-01T22:50:17 Z MohamedAliSaidane 슈퍼트리 잇기 (IOI20_supertrees) C++14
40 / 100
280 ms 31900 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define popb pop_back
#define ff first
#define ss second

vi par;
vi rnk;
int findset(int i)
{
    if(par[i] == i)
        return i;
    return findset(par[i]) ;
}
void unite(int i, int j)
{
    if(findset(i) == findset(j))
        return;
    int x = findset(i);
    int y = findset(j);
    if(rnk[x] < rnk[y])
        swap(x,y);
    par[y] = x;
    if(rnk[x] == rnk[y])
        rnk[x] ++;
    return ;
}
int construct(vector<vi> p)
 {
	int n = p.size();
	vector<vi> b;
	int maxt = 0;
	map<int,vi> m;
	for (int i = 0; i < n; i++)
    {
		vi row;
		for(int j = 0; j <n; j ++)
        {
            par.pb(j);
            rnk.pb(0);
            row.pb(0);
        }
		b.pb(row);
	}
	for(int i = 0; i <n; i ++)
	{
	    for(int j = 0; j < n; j ++)
        {
            if(i == j)
            {
                continue;
            }
            if(p[i][j] > 0)
            {
                maxt = max(p[i][j],maxt);
                unite(i,j);
            }
        }
	}
	for(int i = 0; i <n; i ++)
    {
        for(int j = 0; j < n; j ++)
        {
            if(i == j)
                continue;
            if((p[i][j] == 0 && findset(i) == findset(j)) || p[i][j] == 3)
                return 0;
        }
    }
    if(maxt == 1)
    {
        for(int i = 0; i <n; i ++)
        {
            if(i != par[i])
            {
                b[i][par[i]] = 1;
                b[par[i]][i] = 1;
            }
        }
    }
    else if (maxt == 2)
    {
        for(int i = 0; i <n ; i++)
        {
            m[findset(i)].pb(i);
        }
        for(auto e: m )
        {
            if(e.ss.size() == 1)
                continue;
            if(e.ss.size() == 2)
                return 0;
            for(int j = 0; j < e.ss.size() - 1; j ++)
            {
                b[e.ss[j]][e.ss[j+1]] = 1;
                b[e.ss[j+1]][e.ss[j]] = 1;
            }
                b[e.ss[0]][e.ss[e.ss.size()-1]] = 1;
                b[e.ss[e.ss.size()-1]][e.ss[0]] = 1;
        }
    }
    build(b);
	return 1;
}
/*
6
1 1 1 0 0 0
1 1 1 0 0 0
1 1 1 0 0 0
0 0 0 1 1 1
0 0 0 1 1 1
0 0 0 1 1 1
*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:98:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |             for(int j = 0; j < e.ss.size() - 1; j ++)
      |                            ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1420 KB Output is correct
7 Correct 249 ms 29788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1420 KB Output is correct
7 Correct 249 ms 29788 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1420 KB Output is correct
13 Correct 239 ms 29780 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 1172 KB Output is correct
17 Correct 125 ms 19936 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 64 ms 7720 KB Output is correct
21 Correct 253 ms 29904 KB Output is correct
22 Correct 240 ms 29884 KB Output is correct
23 Correct 280 ms 29796 KB Output is correct
24 Correct 255 ms 29788 KB Output is correct
25 Correct 114 ms 20072 KB Output is correct
26 Correct 109 ms 19948 KB Output is correct
27 Correct 262 ms 29792 KB Output is correct
28 Correct 251 ms 29956 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 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 10 ms 1420 KB Output is correct
9 Correct 243 ms 29784 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1504 KB Output is correct
13 Correct 252 ms 29804 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 1172 KB Output is correct
17 Correct 135 ms 19960 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 69 ms 7712 KB Output is correct
22 Correct 249 ms 31828 KB Output is correct
23 Correct 269 ms 31900 KB Output is correct
24 Correct 263 ms 31820 KB Output is correct
25 Correct 114 ms 21972 KB Output is correct
26 Correct 114 ms 21980 KB Output is correct
27 Correct 244 ms 31832 KB Output is correct
28 Correct 256 ms 31740 KB Output is correct
29 Correct 111 ms 21928 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 0 ms 204 KB Output is correct
4 Correct 67 ms 7716 KB Output is correct
5 Correct 247 ms 29824 KB Output is correct
6 Correct 244 ms 29852 KB Output is correct
7 Correct 257 ms 29856 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 61 ms 7660 KB Output is correct
10 Correct 246 ms 31828 KB Output is correct
11 Correct 248 ms 31816 KB Output is correct
12 Correct 257 ms 31764 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Incorrect 1 ms 204 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1420 KB Output is correct
7 Correct 249 ms 29788 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1420 KB Output is correct
13 Correct 239 ms 29780 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 1172 KB Output is correct
17 Correct 125 ms 19936 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 64 ms 7720 KB Output is correct
21 Correct 253 ms 29904 KB Output is correct
22 Correct 240 ms 29884 KB Output is correct
23 Correct 280 ms 29796 KB Output is correct
24 Correct 255 ms 29788 KB Output is correct
25 Correct 114 ms 20072 KB Output is correct
26 Correct 109 ms 19948 KB Output is correct
27 Correct 262 ms 29792 KB Output is correct
28 Correct 251 ms 29956 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 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1420 KB Output is correct
37 Correct 243 ms 29784 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1504 KB Output is correct
41 Correct 252 ms 29804 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 6 ms 1172 KB Output is correct
45 Correct 135 ms 19960 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 69 ms 7712 KB Output is correct
50 Correct 249 ms 31828 KB Output is correct
51 Correct 269 ms 31900 KB Output is correct
52 Correct 263 ms 31820 KB Output is correct
53 Correct 114 ms 21972 KB Output is correct
54 Correct 114 ms 21980 KB Output is correct
55 Correct 244 ms 31832 KB Output is correct
56 Correct 256 ms 31740 KB Output is correct
57 Correct 111 ms 21928 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 6 ms 1300 KB Output is correct
61 Correct 129 ms 21980 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Incorrect 1 ms 204 KB Too many ways to get from 0 to 9, should be 1 found no less than 2
64 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1420 KB Output is correct
7 Correct 249 ms 29788 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1420 KB Output is correct
13 Correct 239 ms 29780 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 1172 KB Output is correct
17 Correct 125 ms 19936 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 64 ms 7720 KB Output is correct
21 Correct 253 ms 29904 KB Output is correct
22 Correct 240 ms 29884 KB Output is correct
23 Correct 280 ms 29796 KB Output is correct
24 Correct 255 ms 29788 KB Output is correct
25 Correct 114 ms 20072 KB Output is correct
26 Correct 109 ms 19948 KB Output is correct
27 Correct 262 ms 29792 KB Output is correct
28 Correct 251 ms 29956 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 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1420 KB Output is correct
37 Correct 243 ms 29784 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1504 KB Output is correct
41 Correct 252 ms 29804 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 6 ms 1172 KB Output is correct
45 Correct 135 ms 19960 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 69 ms 7712 KB Output is correct
50 Correct 249 ms 31828 KB Output is correct
51 Correct 269 ms 31900 KB Output is correct
52 Correct 263 ms 31820 KB Output is correct
53 Correct 114 ms 21972 KB Output is correct
54 Correct 114 ms 21980 KB Output is correct
55 Correct 244 ms 31832 KB Output is correct
56 Correct 256 ms 31740 KB Output is correct
57 Correct 111 ms 21928 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 67 ms 7716 KB Output is correct
62 Correct 247 ms 29824 KB Output is correct
63 Correct 244 ms 29852 KB Output is correct
64 Correct 257 ms 29856 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 61 ms 7660 KB Output is correct
67 Correct 246 ms 31828 KB Output is correct
68 Correct 248 ms 31816 KB Output is correct
69 Correct 257 ms 31764 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Incorrect 1 ms 204 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
72 Halted 0 ms 0 KB -