Submission #756338

# Submission time Handle Problem Language Result Execution time Memory
756338 2023-06-11T14:16:49 Z Trumling Connecting Supertrees (IOI20_supertrees) C++14
96 / 100
213 ms 26960 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std; 

typedef long long ll;
#define pb push_back
#define F first
#define S second
#define enter cout<<'\n';
#define INF 99999999999999999
#define MOD 1000000007
#define all(x) x.begin(),x.end()

vector<bool>vis(1000,0);
vector<bool>vis2(1000,0);

vector<vector<int>>g;
vector<vector<int>>ans;
ll nn;

bool dfs1(int start,int beg)
{
	vis[start]=1;
	for(int i=0;i<nn;i++)
		if(g[start][i]!=g[beg][i] && i!=start && i!=beg)
			return 0;

	for(int i=0;i<nn;i++)
		if(!vis[i] && g[start][i]==1)
		{
			ans[i][start]=1;
			ans[start][i]=1;
			return dfs1(i,beg);
		}

	vis[beg]=0;

	return 1;
}

bool dfs2(int start,int beg)
{
	vis[start]=1;
	if(start!=beg)
	for(int i=0;i<nn;i++)
	{
		if(g[start][i]==1 && g[beg][i]==1)
		return 0;

		if(g[start][i]==2 && g[beg][i]==0 || g[start][i]==0 && g[beg][i]==2)
		return 0;

		if(g[start][i]==1 && g[beg][i]==0 || g[start][i]==0 && g[beg][i]==1)
		return 0;
	}
	

	for(int i=0;i<nn;i++)
		if(!vis[i] && g[start][i]==2)
		{
			ans[i][start]=1;
			ans[start][i]=1;

			return dfs2(i,beg);
		}
	ans[start][beg]=1;
	ans[beg][start]=1;
	return 1;
}

int construct(vector<vector<int>> pr) 
{
	nn=pr.size();
	g=pr;

	ans.assign(nn,vector<int>(nn,0));

	for(int i=0;i<nn;i++)
	{
		bool now=dfs1(i,i);
		if(!now)
		return 0;
	}

	for(int i=0;i<nn;i++)
	{
		if(vis[i])
		continue;
		
		ll count=0;
		for(int j=0;j<nn;j++)
		if(g[i][j]==2 && !vis[j])
		count++;

		if(count==1)
		return 0;

		bool now=dfs2(i,i);
		if(!now)
		return 0;
	}

	for(int i=0;i<nn;i++)
	ans[i][i]=0;

	build(ans);
	return 1;

}

Compilation message

supertrees.cpp: In function 'bool dfs2(int, int)':
supertrees.cpp:50:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   50 |   if(g[start][i]==2 && g[beg][i]==0 || g[start][i]==0 && g[beg][i]==2)
supertrees.cpp:53:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   53 |   if(g[start][i]==1 && g[beg][i]==0 || g[start][i]==0 && g[beg][i]==1)
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1344 KB Output is correct
7 Correct 168 ms 25880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1344 KB Output is correct
7 Correct 168 ms 25880 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 197 ms 26068 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 76 ms 16008 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 46 ms 6836 KB Output is correct
21 Correct 188 ms 25876 KB Output is correct
22 Correct 173 ms 25924 KB Output is correct
23 Correct 197 ms 25988 KB Output is correct
24 Correct 168 ms 26004 KB Output is correct
25 Correct 68 ms 16004 KB Output is correct
26 Correct 68 ms 16080 KB Output is correct
27 Correct 175 ms 26000 KB Output is correct
28 Correct 164 ms 25936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 8 ms 1424 KB Output is correct
9 Correct 171 ms 26896 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 8 ms 1392 KB Output is correct
13 Correct 172 ms 26852 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 77 ms 17012 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 43 ms 7180 KB Output is correct
22 Correct 187 ms 26900 KB Output is correct
23 Correct 180 ms 26956 KB Output is correct
24 Correct 182 ms 26956 KB Output is correct
25 Correct 70 ms 17016 KB Output is correct
26 Correct 72 ms 16972 KB Output is correct
27 Correct 178 ms 26960 KB Output is correct
28 Correct 184 ms 26936 KB Output is correct
29 Correct 75 ms 17100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 47 ms 6740 KB Output is correct
5 Correct 192 ms 25996 KB Output is correct
6 Correct 178 ms 25960 KB Output is correct
7 Correct 213 ms 26000 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 42 ms 6732 KB Output is correct
10 Correct 172 ms 25888 KB Output is correct
11 Correct 174 ms 25948 KB Output is correct
12 Correct 179 ms 25984 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 64 ms 6716 KB Output is correct
17 Correct 193 ms 25944 KB Output is correct
18 Correct 178 ms 25948 KB Output is correct
19 Correct 192 ms 25984 KB Output is correct
20 Correct 170 ms 25992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1344 KB Output is correct
7 Correct 168 ms 25880 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 197 ms 26068 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 76 ms 16008 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 46 ms 6836 KB Output is correct
21 Correct 188 ms 25876 KB Output is correct
22 Correct 173 ms 25924 KB Output is correct
23 Correct 197 ms 25988 KB Output is correct
24 Correct 168 ms 26004 KB Output is correct
25 Correct 68 ms 16004 KB Output is correct
26 Correct 68 ms 16080 KB Output is correct
27 Correct 175 ms 26000 KB Output is correct
28 Correct 164 ms 25936 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1424 KB Output is correct
37 Correct 171 ms 26896 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 300 KB Output is correct
40 Correct 8 ms 1392 KB Output is correct
41 Correct 172 ms 26852 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 980 KB Output is correct
45 Correct 77 ms 17012 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 43 ms 7180 KB Output is correct
50 Correct 187 ms 26900 KB Output is correct
51 Correct 180 ms 26956 KB Output is correct
52 Correct 182 ms 26956 KB Output is correct
53 Correct 70 ms 17016 KB Output is correct
54 Correct 72 ms 16972 KB Output is correct
55 Correct 178 ms 26960 KB Output is correct
56 Correct 184 ms 26936 KB Output is correct
57 Correct 75 ms 17100 KB Output is correct
58 Correct 1 ms 280 KB Output is correct
59 Correct 1 ms 300 KB Output is correct
60 Correct 4 ms 980 KB Output is correct
61 Correct 83 ms 17012 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 304 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 44 ms 7244 KB Output is correct
66 Correct 73 ms 18044 KB Output is correct
67 Correct 82 ms 18032 KB Output is correct
68 Correct 72 ms 17920 KB Output is correct
69 Correct 72 ms 17984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1344 KB Output is correct
7 Correct 168 ms 25880 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 197 ms 26068 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 76 ms 16008 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 46 ms 6836 KB Output is correct
21 Correct 188 ms 25876 KB Output is correct
22 Correct 173 ms 25924 KB Output is correct
23 Correct 197 ms 25988 KB Output is correct
24 Correct 168 ms 26004 KB Output is correct
25 Correct 68 ms 16004 KB Output is correct
26 Correct 68 ms 16080 KB Output is correct
27 Correct 175 ms 26000 KB Output is correct
28 Correct 164 ms 25936 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1424 KB Output is correct
37 Correct 171 ms 26896 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 300 KB Output is correct
40 Correct 8 ms 1392 KB Output is correct
41 Correct 172 ms 26852 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 980 KB Output is correct
45 Correct 77 ms 17012 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 43 ms 7180 KB Output is correct
50 Correct 187 ms 26900 KB Output is correct
51 Correct 180 ms 26956 KB Output is correct
52 Correct 182 ms 26956 KB Output is correct
53 Correct 70 ms 17016 KB Output is correct
54 Correct 72 ms 16972 KB Output is correct
55 Correct 178 ms 26960 KB Output is correct
56 Correct 184 ms 26936 KB Output is correct
57 Correct 75 ms 17100 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 47 ms 6740 KB Output is correct
62 Correct 192 ms 25996 KB Output is correct
63 Correct 178 ms 25960 KB Output is correct
64 Correct 213 ms 26000 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 42 ms 6732 KB Output is correct
67 Correct 172 ms 25888 KB Output is correct
68 Correct 174 ms 25948 KB Output is correct
69 Correct 179 ms 25984 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 64 ms 6716 KB Output is correct
74 Correct 193 ms 25944 KB Output is correct
75 Correct 178 ms 25948 KB Output is correct
76 Correct 192 ms 25984 KB Output is correct
77 Correct 170 ms 25992 KB Output is correct
78 Correct 1 ms 280 KB Output is correct
79 Correct 1 ms 300 KB Output is correct
80 Correct 4 ms 980 KB Output is correct
81 Correct 83 ms 17012 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 304 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 44 ms 7244 KB Output is correct
86 Correct 73 ms 18044 KB Output is correct
87 Correct 82 ms 18032 KB Output is correct
88 Correct 72 ms 17920 KB Output is correct
89 Correct 72 ms 17984 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 4 ms 980 KB Output is correct
93 Correct 84 ms 18028 KB Output is correct
94 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -