Submission #302780

# Submission time Handle Problem Language Result Execution time Memory
302780 2020-09-19T07:52:33 Z mhy908 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
272 ms 30220 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(all(x))
#define press(x) x.erase(unique(all(x)), x.end());
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
const int INF=1e9;
const LL LLINF=1e18;

int n, arr[1010][1010], ans[1010][1010], tnum[1010];

struct UNION_FIND{
    int par[1010];
    UNION_FIND(){for(int i=1; i<=1000; i++)par[i]=i;}
    int findpar(int a){return a==par[a]?a:par[a]=findpar(par[a]);}
    void mergepar(int a, int b){par[findpar(a)]=findpar(b);}
}cyc, tree;

vector<int> rt[1010];

int construct(vector<vector<int> > p){
	n=p.size();
	for(int i=0; i<n; i++){
        for(int j=0; j<n; j++)arr[i+1][j+1]=p[i][j];
	}
	for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(arr[i][j]==3)return 0;
        }
        if(arr[i][i]!=1)return 0;
	}
	for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(arr[i][j]==1&&i!=j)tree.mergepar(i, j);
        }
	}
	for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(tree.findpar(i)==tree.findpar(j)&&arr[i][j]!=1)return 0;
        }
	}
	for(int i=1; i<=n; i++)tnum[i]=tree.findpar(i);
	for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(arr[i][j]==2)cyc.mergepar(tnum[i], tnum[j]);
        }
	}
	for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(tnum[i]==tnum[j])continue;
            if(cyc.findpar(tnum[i])==cyc.findpar(tnum[j])&&arr[i][j]!=2)return 0;
        }
	}
	for(int i=1; i<=n; i++){
        rt[cyc.findpar(tnum[i])].eb(tnum[i]);
        if(i==tnum[i])continue;
        ans[i][tnum[i]]=1;
        ans[tnum[i]][i]=1;
	}
	for(int i=1; i<=n; i++){
        svec(rt[i]);
        press(rt[i]);
        if(rt[i].size()<=1)continue;
        if(rt[i].size()==2)return 0;
        for(int j=0; j<rt[i].size()-1; j++){
            ans[rt[i][j]][rt[i][j+1]]=1;
            ans[rt[i][j+1]][rt[i][j]]=1;
        }
        ans[rt[i][0]][rt[i].back()]=1;
        ans[rt[i].back()][rt[i][0]]=1;
	}
	vector<vector<int> > ret;
	for(int i=1; i<=n; i++){
		vector<int> vc;
		vc.resize(n);
		for(int j=1; j<=n; j++){
            if(ans[i][j])vc[j-1]=1;
		}
		ret.push_back(vc);
	}
	build(ret);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for(int j=0; j<rt[i].size()-1; j++){
      |                      ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 2816 KB Output is correct
7 Correct 251 ms 30072 KB Output is correct
# Verdict Execution time Memory 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 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 2816 KB Output is correct
7 Correct 251 ms 30072 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 242 ms 26232 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 1408 KB Output is correct
17 Correct 113 ms 12152 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 64 ms 9624 KB Output is correct
21 Correct 252 ms 30072 KB Output is correct
22 Correct 246 ms 29560 KB Output is correct
23 Correct 266 ms 30072 KB Output is correct
24 Correct 254 ms 26360 KB Output is correct
25 Correct 103 ms 12152 KB Output is correct
26 Correct 102 ms 12152 KB Output is correct
27 Correct 262 ms 30072 KB Output is correct
28 Correct 241 ms 26360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 11 ms 2048 KB Output is correct
9 Correct 258 ms 26108 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 11 ms 2816 KB Output is correct
13 Correct 251 ms 30072 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1408 KB Output is correct
17 Correct 113 ms 12152 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 64 ms 9724 KB Output is correct
22 Correct 258 ms 30072 KB Output is correct
23 Correct 249 ms 30072 KB Output is correct
24 Correct 258 ms 30072 KB Output is correct
25 Correct 103 ms 12280 KB Output is correct
26 Correct 101 ms 12284 KB Output is correct
27 Correct 245 ms 30072 KB Output is correct
28 Correct 257 ms 30076 KB Output is correct
29 Correct 102 ms 12280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 63 ms 9592 KB Output is correct
5 Correct 252 ms 30072 KB Output is correct
6 Correct 246 ms 29560 KB Output is correct
7 Correct 272 ms 30072 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 65 ms 9720 KB Output is correct
10 Correct 256 ms 30072 KB Output is correct
11 Correct 248 ms 30220 KB Output is correct
12 Correct 258 ms 30072 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 416 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 64 ms 9720 KB Output is correct
17 Correct 249 ms 30076 KB Output is correct
18 Correct 252 ms 29688 KB Output is correct
19 Correct 250 ms 29656 KB Output is correct
20 Correct 240 ms 26360 KB Output is correct
# Verdict Execution time Memory 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 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 2816 KB Output is correct
7 Correct 251 ms 30072 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 242 ms 26232 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 1408 KB Output is correct
17 Correct 113 ms 12152 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 64 ms 9624 KB Output is correct
21 Correct 252 ms 30072 KB Output is correct
22 Correct 246 ms 29560 KB Output is correct
23 Correct 266 ms 30072 KB Output is correct
24 Correct 254 ms 26360 KB Output is correct
25 Correct 103 ms 12152 KB Output is correct
26 Correct 102 ms 12152 KB Output is correct
27 Correct 262 ms 30072 KB Output is correct
28 Correct 241 ms 26360 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 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 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 2048 KB Output is correct
37 Correct 258 ms 26108 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 11 ms 2816 KB Output is correct
41 Correct 251 ms 30072 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 1408 KB Output is correct
45 Correct 113 ms 12152 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 64 ms 9724 KB Output is correct
50 Correct 258 ms 30072 KB Output is correct
51 Correct 249 ms 30072 KB Output is correct
52 Correct 258 ms 30072 KB Output is correct
53 Correct 103 ms 12280 KB Output is correct
54 Correct 101 ms 12284 KB Output is correct
55 Correct 245 ms 30072 KB Output is correct
56 Correct 257 ms 30076 KB Output is correct
57 Correct 102 ms 12280 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 5 ms 1408 KB Output is correct
61 Correct 135 ms 12152 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 64 ms 9720 KB Output is correct
66 Correct 104 ms 12152 KB Output is correct
67 Correct 98 ms 12152 KB Output is correct
68 Correct 105 ms 12152 KB Output is correct
69 Correct 104 ms 12408 KB Output is correct
# Verdict Execution time Memory 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 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 2816 KB Output is correct
7 Correct 251 ms 30072 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 242 ms 26232 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 1408 KB Output is correct
17 Correct 113 ms 12152 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 64 ms 9624 KB Output is correct
21 Correct 252 ms 30072 KB Output is correct
22 Correct 246 ms 29560 KB Output is correct
23 Correct 266 ms 30072 KB Output is correct
24 Correct 254 ms 26360 KB Output is correct
25 Correct 103 ms 12152 KB Output is correct
26 Correct 102 ms 12152 KB Output is correct
27 Correct 262 ms 30072 KB Output is correct
28 Correct 241 ms 26360 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 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 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 2048 KB Output is correct
37 Correct 258 ms 26108 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 11 ms 2816 KB Output is correct
41 Correct 251 ms 30072 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 1408 KB Output is correct
45 Correct 113 ms 12152 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 64 ms 9724 KB Output is correct
50 Correct 258 ms 30072 KB Output is correct
51 Correct 249 ms 30072 KB Output is correct
52 Correct 258 ms 30072 KB Output is correct
53 Correct 103 ms 12280 KB Output is correct
54 Correct 101 ms 12284 KB Output is correct
55 Correct 245 ms 30072 KB Output is correct
56 Correct 257 ms 30076 KB Output is correct
57 Correct 102 ms 12280 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 0 ms 384 KB Output is correct
61 Correct 63 ms 9592 KB Output is correct
62 Correct 252 ms 30072 KB Output is correct
63 Correct 246 ms 29560 KB Output is correct
64 Correct 272 ms 30072 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 65 ms 9720 KB Output is correct
67 Correct 256 ms 30072 KB Output is correct
68 Correct 248 ms 30220 KB Output is correct
69 Correct 258 ms 30072 KB Output is correct
70 Correct 0 ms 384 KB Output is correct
71 Correct 1 ms 416 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 64 ms 9720 KB Output is correct
74 Correct 249 ms 30076 KB Output is correct
75 Correct 252 ms 29688 KB Output is correct
76 Correct 250 ms 29656 KB Output is correct
77 Correct 240 ms 26360 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 5 ms 1408 KB Output is correct
81 Correct 135 ms 12152 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 64 ms 9720 KB Output is correct
86 Correct 104 ms 12152 KB Output is correct
87 Correct 98 ms 12152 KB Output is correct
88 Correct 105 ms 12152 KB Output is correct
89 Correct 104 ms 12408 KB Output is correct
90 Correct 0 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 5 ms 1408 KB Output is correct
93 Correct 103 ms 12152 KB Output is correct
94 Correct 1 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 25 ms 4352 KB Output is correct
98 Correct 96 ms 12152 KB Output is correct
99 Correct 96 ms 12156 KB Output is correct
100 Correct 96 ms 12152 KB Output is correct
101 Correct 96 ms 12280 KB Output is correct
102 Correct 97 ms 12152 KB Output is correct
103 Correct 97 ms 12152 KB Output is correct
104 Correct 98 ms 12152 KB Output is correct
105 Correct 104 ms 12280 KB Output is correct