답안 #928012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928012 2024-02-15T17:26:26 Z velislavgarkov 슈퍼트리 잇기 (IOI20_supertrees) C++14
56 / 100
175 ms 28244 KB
#include "supertrees.h"
#include <iostream>
#include <vector>
using namespace std;
const int MAXN=1e3+10;
vector<vector<int> > ans;
vector <int> v[MAXN], ones, ch, comp[MAXN];
int par[MAXN], d[MAXN];
bool used[MAXN], fl;
int root(int x) {
	if (x==par[x]) return x;
	return par[x]=root(par[x]);
}
void connect(int a, int b) {
	int ra, rb;
	ra=root(a);
	rb=root(b);
	if (ra==rb) return;
	if (d[ra]>d[rb]) par[rb]=ra;
	else if (d[rb]>d[ra]) par[ra]=rb;
	else {
		par[rb]=ra;
		d[ra]++;
	}
}
void find_comp(int x) {
	used[x]=true;
	ch.push_back(x);
	for (auto i:v[x]) {
		if (used[i]) continue;
		find_comp(i);
	}
}
void add_edge(int a, int b) {
	ans[a][b]=ans[b][a]=1;
}
int construct(vector<vector<int> > p) {
	int n = p.size();
	ans.resize(n);
	fl=true;
	for (int i=0;i<n;i++) {
		if (p[i][i]!=1) fl=false;
		for (int j=i+1;j<n;j++) {
			if (p[i][j]==3) fl=false;
			if (p[i][j]) {
				v[i].push_back(j);
				v[j].push_back(i);
			}
		}
		par[i]=i;
		d[i]=used[i]=0;
		ans[i].resize(n);
		for (int j=0;j<n;j++) ans[i][j]=0;
	}
	if (!fl) return 0;
	for (int x=0;x<n;x++) {
		if (used[x]) continue;
		if (!ch.empty()) ch.clear();
		find_comp(x);
		if (ch.size()==1) continue;
		for (int i=0;i<ch.size();i++) {
			for (int j=i+1;j<ch.size();j++) {
				if (p[ch[i]][ch[j]]==0) fl=false;
				else if (p[ch[i]][ch[j]]==1) connect(ch[i],ch[j]);
			}
		}
		if (!ones.empty()) ones.clear();
		for (int i=0;i<ch.size();i++) {
			int ri=root(ch[i]);
			if (comp[ri].empty()) ones.push_back(ri);
			comp[ri].push_back(ch[i]);
		}
		for (int i=0;i<ones.size();i++) {
			int nxt=(i-1+ones.size())%ones.size();
			if (nxt!=i) add_edge(ones[i],ones[nxt]);
			int cur=ones[i];
			for (int j=0;j<comp[cur].size();j++) {
				if (j>0) add_edge(comp[cur][j-1],comp[cur][j]);
				for (int k=1;k<comp[cur].size();k++) {
					if (p[comp[cur][j]][comp[cur][j]]==2) fl=false;
				}
			}
		}
	}
	if (!fl) return 0;
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:61:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for (int i=0;i<ch.size();i++) {
      |                ~^~~~~~~~~~
supertrees.cpp:62:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |    for (int j=i+1;j<ch.size();j++) {
      |                   ~^~~~~~~~~~
supertrees.cpp:68:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for (int i=0;i<ch.size();i++) {
      |                ~^~~~~~~~~~
supertrees.cpp:73:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for (int i=0;i<ones.size();i++) {
      |                ~^~~~~~~~~~~~
supertrees.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |    for (int j=0;j<comp[cur].size();j++) {
      |                 ~^~~~~~~~~~~~~~~~~
supertrees.cpp:79:19: 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=1;k<comp[cur].size();k++) {
      |                  ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 8 ms 1648 KB Output is correct
7 Correct 175 ms 28244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 8 ms 1648 KB Output is correct
7 Correct 175 ms 28244 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 7 ms 1436 KB Output is correct
13 Correct 162 ms 23972 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1116 KB Output is correct
17 Correct 85 ms 17492 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 40 ms 6484 KB Output is correct
21 Correct 162 ms 24664 KB Output is correct
22 Correct 168 ms 24196 KB Output is correct
23 Correct 172 ms 26192 KB Output is correct
24 Correct 161 ms 23980 KB Output is correct
25 Correct 72 ms 14764 KB Output is correct
26 Correct 66 ms 14160 KB Output is correct
27 Correct 174 ms 27276 KB Output is correct
28 Correct 169 ms 23956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 39 ms 6308 KB Output is correct
5 Correct 166 ms 24748 KB Output is correct
6 Correct 158 ms 24144 KB Output is correct
7 Correct 160 ms 26284 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 39 ms 6272 KB Output is correct
10 Correct 156 ms 24580 KB Output is correct
11 Correct 155 ms 24120 KB Output is correct
12 Correct 161 ms 27180 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 41 ms 6392 KB Output is correct
17 Correct 166 ms 24808 KB Output is correct
18 Correct 157 ms 24720 KB Output is correct
19 Correct 155 ms 24244 KB Output is correct
20 Correct 158 ms 24068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 8 ms 1648 KB Output is correct
7 Correct 175 ms 28244 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 7 ms 1436 KB Output is correct
13 Correct 162 ms 23972 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1116 KB Output is correct
17 Correct 85 ms 17492 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 40 ms 6484 KB Output is correct
21 Correct 162 ms 24664 KB Output is correct
22 Correct 168 ms 24196 KB Output is correct
23 Correct 172 ms 26192 KB Output is correct
24 Correct 161 ms 23980 KB Output is correct
25 Correct 72 ms 14764 KB Output is correct
26 Correct 66 ms 14160 KB Output is correct
27 Correct 174 ms 27276 KB Output is correct
28 Correct 169 ms 23956 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 8 ms 1648 KB Output is correct
7 Correct 175 ms 28244 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 7 ms 1436 KB Output is correct
13 Correct 162 ms 23972 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1116 KB Output is correct
17 Correct 85 ms 17492 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 40 ms 6484 KB Output is correct
21 Correct 162 ms 24664 KB Output is correct
22 Correct 168 ms 24196 KB Output is correct
23 Correct 172 ms 26192 KB Output is correct
24 Correct 161 ms 23980 KB Output is correct
25 Correct 72 ms 14764 KB Output is correct
26 Correct 66 ms 14160 KB Output is correct
27 Correct 174 ms 27276 KB Output is correct
28 Correct 169 ms 23956 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -