답안 #439880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439880 2021-07-01T05:00:20 Z adamjinwei 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
306 ms 27972 KB
#include <bits/stdc++.h>
#include "supertrees.h"
#define inf 1000000007
#define mod 1000000007
#define rnd() rand_num()
#define bigrnd() dis(rand_num)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
//#define int long long
using namespace std;
unsigned sed=std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(sed);
uniform_int_distribution<long long> dis(0,inf);
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n;
int fa[1005];
int fa1[1005];
int g[1005][1005];
int fnd(int x)
{
	if(fa[x]!=x) fa[x]=fnd(fa[x]);
	return fa[x];
}
int fnd1(int x)
{
	if(fa1[x]!=x) fa1[x]=fnd1(fa1[x]);
	return fa1[x];
}
int construct(vector<vector<int>> p)
{
	n=p.size();
	for(int i=0;i<n;++i)
		fa[i]=i;
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			if(p[i][j]==3)
				return 0;
			else if(p[i][j])
				fa[fnd(i)]=fnd(j);
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			if(!p[i][j]&&fnd(i)==fnd(j))
				return 0;
	for(int i=0;i<n;++i)
		fa1[i]=i;
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			if(p[i][j]==1)
				fa1[fnd1(i)]=fnd1(j);
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			if(p[i][j]==2&&fnd1(i)==fnd1(j))
				return 0;
	for(int i=0;i<n;++i)
		if(fnd(i)==i)
		{
			vector<int> vec;
			for(int j=0;j<n;++j)
				if(fnd(j)==i)
					vec.push_back(fnd1(j));
			sort(vec.begin(),vec.end());
			vec.erase(unique(vec.begin(),vec.end()),vec.end());
			bool flag=false;
			for(int j=0;j<vec.size();++j)
				for(int k=j+1;k<vec.size();++k)
					if(p[vec[j]][vec[k]]==2)
						flag=true;
			if(flag&&vec.size()<3) return 0;
			if(flag)
			{
				for(int j=0;j+1<vec.size();++j)
					g[vec[j]][vec[j+1]]=g[vec[j+1]][vec[j]]=1;
				g[vec[0]][vec[vec.size()-1]]=g[vec[vec.size()-1]][vec[0]]=1;
			}
			for(int j=0;j<n;++j)
				if(fnd1(j)!=j)
					g[fnd1(j)][j]=g[j][fnd1(j)]=1;
		}
	vector<vector<int>> ans;
	for(int i=0;i<n;++i)
	{
		vector<int> tmp;
		for(int j=0;j<n;++j)
			tmp.push_back(g[i][j]);
		ans.push_back(tmp);
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:78:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |    for(int j=0;j<vec.size();++j)
      |                ~^~~~~~~~~~~
supertrees.cpp:79:20: 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=j+1;k<vec.size();++k)
      |                   ~^~~~~~~~~~~
supertrees.cpp:85:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for(int j=0;j+1<vec.size();++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 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 12 ms 1996 KB Output is correct
7 Correct 236 ms 26008 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 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 12 ms 1996 KB Output is correct
7 Correct 236 ms 26008 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 232 ms 22036 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 588 KB Output is correct
17 Correct 126 ms 8076 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 60 ms 7536 KB Output is correct
21 Correct 235 ms 25904 KB Output is correct
22 Correct 287 ms 25360 KB Output is correct
23 Correct 281 ms 25952 KB Output is correct
24 Correct 244 ms 22244 KB Output is correct
25 Correct 98 ms 8132 KB Output is correct
26 Correct 92 ms 8092 KB Output is correct
27 Correct 261 ms 25896 KB Output is correct
28 Correct 234 ms 22248 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 1176 KB Output is correct
9 Correct 244 ms 22044 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1916 KB Output is correct
13 Correct 250 ms 25924 KB Output is correct
14 Correct 1 ms 248 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 8 ms 592 KB Output is correct
17 Correct 130 ms 8088 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 60 ms 7608 KB Output is correct
22 Correct 246 ms 25992 KB Output is correct
23 Correct 246 ms 25928 KB Output is correct
24 Correct 306 ms 26004 KB Output is correct
25 Correct 108 ms 8192 KB Output is correct
26 Correct 96 ms 8084 KB Output is correct
27 Correct 235 ms 25880 KB Output is correct
28 Correct 255 ms 26052 KB Output is correct
29 Correct 103 ms 8260 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 332 KB Output is correct
4 Correct 80 ms 7564 KB Output is correct
5 Correct 241 ms 25992 KB Output is correct
6 Correct 244 ms 25412 KB Output is correct
7 Correct 262 ms 25980 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 66 ms 7528 KB Output is correct
10 Correct 245 ms 27972 KB Output is correct
11 Correct 230 ms 27844 KB Output is correct
12 Correct 254 ms 27844 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 64 ms 8048 KB Output is correct
17 Correct 243 ms 27904 KB Output is correct
18 Correct 252 ms 27556 KB Output is correct
19 Correct 234 ms 27528 KB Output is correct
20 Correct 243 ms 24212 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 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 12 ms 1996 KB Output is correct
7 Correct 236 ms 26008 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 232 ms 22036 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 588 KB Output is correct
17 Correct 126 ms 8076 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 60 ms 7536 KB Output is correct
21 Correct 235 ms 25904 KB Output is correct
22 Correct 287 ms 25360 KB Output is correct
23 Correct 281 ms 25952 KB Output is correct
24 Correct 244 ms 22244 KB Output is correct
25 Correct 98 ms 8132 KB Output is correct
26 Correct 92 ms 8092 KB Output is correct
27 Correct 261 ms 25896 KB Output is correct
28 Correct 234 ms 22248 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 1176 KB Output is correct
37 Correct 244 ms 22044 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 11 ms 1916 KB Output is correct
41 Correct 250 ms 25924 KB Output is correct
42 Correct 1 ms 248 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 8 ms 592 KB Output is correct
45 Correct 130 ms 8088 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 60 ms 7608 KB Output is correct
50 Correct 246 ms 25992 KB Output is correct
51 Correct 246 ms 25928 KB Output is correct
52 Correct 306 ms 26004 KB Output is correct
53 Correct 108 ms 8192 KB Output is correct
54 Correct 96 ms 8084 KB Output is correct
55 Correct 235 ms 25880 KB Output is correct
56 Correct 255 ms 26052 KB Output is correct
57 Correct 103 ms 8260 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 5 ms 716 KB Output is correct
61 Correct 111 ms 10116 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 60 ms 8052 KB Output is correct
66 Correct 100 ms 10032 KB Output is correct
67 Correct 95 ms 10052 KB Output is correct
68 Correct 99 ms 10052 KB Output is correct
69 Correct 102 ms 10232 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 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 12 ms 1996 KB Output is correct
7 Correct 236 ms 26008 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 232 ms 22036 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 588 KB Output is correct
17 Correct 126 ms 8076 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 60 ms 7536 KB Output is correct
21 Correct 235 ms 25904 KB Output is correct
22 Correct 287 ms 25360 KB Output is correct
23 Correct 281 ms 25952 KB Output is correct
24 Correct 244 ms 22244 KB Output is correct
25 Correct 98 ms 8132 KB Output is correct
26 Correct 92 ms 8092 KB Output is correct
27 Correct 261 ms 25896 KB Output is correct
28 Correct 234 ms 22248 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 1176 KB Output is correct
37 Correct 244 ms 22044 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 11 ms 1916 KB Output is correct
41 Correct 250 ms 25924 KB Output is correct
42 Correct 1 ms 248 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 8 ms 592 KB Output is correct
45 Correct 130 ms 8088 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 60 ms 7608 KB Output is correct
50 Correct 246 ms 25992 KB Output is correct
51 Correct 246 ms 25928 KB Output is correct
52 Correct 306 ms 26004 KB Output is correct
53 Correct 108 ms 8192 KB Output is correct
54 Correct 96 ms 8084 KB Output is correct
55 Correct 235 ms 25880 KB Output is correct
56 Correct 255 ms 26052 KB Output is correct
57 Correct 103 ms 8260 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 80 ms 7564 KB Output is correct
62 Correct 241 ms 25992 KB Output is correct
63 Correct 244 ms 25412 KB Output is correct
64 Correct 262 ms 25980 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 66 ms 7528 KB Output is correct
67 Correct 245 ms 27972 KB Output is correct
68 Correct 230 ms 27844 KB Output is correct
69 Correct 254 ms 27844 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 64 ms 8048 KB Output is correct
74 Correct 243 ms 27904 KB Output is correct
75 Correct 252 ms 27556 KB Output is correct
76 Correct 234 ms 27528 KB Output is correct
77 Correct 243 ms 24212 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 5 ms 716 KB Output is correct
81 Correct 111 ms 10116 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 1 ms 332 KB Output is correct
85 Correct 60 ms 8052 KB Output is correct
86 Correct 100 ms 10032 KB Output is correct
87 Correct 95 ms 10052 KB Output is correct
88 Correct 99 ms 10052 KB Output is correct
89 Correct 102 ms 10232 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 5 ms 588 KB Output is correct
93 Correct 101 ms 10032 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 24 ms 2692 KB Output is correct
98 Correct 96 ms 10112 KB Output is correct
99 Correct 98 ms 10108 KB Output is correct
100 Correct 92 ms 10120 KB Output is correct
101 Correct 94 ms 10120 KB Output is correct
102 Correct 96 ms 10116 KB Output is correct
103 Correct 95 ms 10032 KB Output is correct
104 Correct 94 ms 10124 KB Output is correct
105 Correct 101 ms 10052 KB Output is correct