Submission #994828

# Submission time Handle Problem Language Result Execution time Memory
994828 2024-06-08T06:58:37 Z Newtonabc Connecting Supertrees (IOI20_supertrees) C++14
56 / 100
133 ms 24148 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
vector<int> v;
int pa[N];
bool cy[N][N];
vector<int> adj[N];
bool vs[N];
void dfs(int u){
	vs[u]=true;
	if(adj[u].size()==1) v.push_back(u);
	for(int i=0;i<adj[u].size();i++){
		if(!vs[adj[u][i]]) dfs(adj[u][i]);
	}
}
int root(int x){
	if(pa[x]==x) return x;
	else return pa[x]=root(pa[x]);
}
int construct(vector<vector<int> > p) {
	int n = p.size();
	vector<vector<int> > answer;
	for (int i = 0; i < n; i++) {
		vector<int> row(n,0);
		answer.push_back(row);
	}
	for(int i=0;i<n;i++) pa[i]=i;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i][j]==1 && root(i)!=root(j)){
				answer[i][j]=1;
				answer[j][i]=1;
				pa[root(i)]=root(j);
			}
			if(p[i][j]==3) return 0;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i][j]==0){
				if(root(i)==root(j)) return 0;
			}
		}
	}
	int cnt=0,cl=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int a,b;
			if(p[i][j]==2){
				a=root(i),b=root(j);
				if(a==b) continue;
				if(answer[a][b]==0) cnt++;
				pa[a]=b;
				answer[a][b]=1;
				answer[b][a]=1;
				adj[a].push_back(b);
				adj[b].push_back(a);
			}
		}
	}
	if(cnt==1) return 0;
	for(int i=0;i<n;i++){
		if(!vs[i]) dfs(i);
		if(v.empty()) continue;
		answer[v[0]][v[1]]=1;
		answer[v[1]][v[0]]=1;
		v.clear();
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:13:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for(int i=0;i<adj[u].size();i++){
      |              ~^~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:46:12: warning: unused variable 'cl' [-Wunused-variable]
   46 |  int cnt=0,cl=0;
      |            ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 111 ms 22056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 111 ms 22056 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1136 KB Output is correct
13 Correct 115 ms 22216 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 72 ms 12308 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 5724 KB Output is correct
21 Correct 122 ms 22096 KB Output is correct
22 Correct 112 ms 22100 KB Output is correct
23 Correct 119 ms 22100 KB Output is correct
24 Correct 121 ms 22100 KB Output is correct
25 Correct 53 ms 12112 KB Output is correct
26 Correct 48 ms 12116 KB Output is correct
27 Correct 123 ms 22128 KB Output is correct
28 Correct 112 ms 22080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1116 KB Output is correct
9 Correct 119 ms 22100 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1408 KB Output is correct
13 Correct 123 ms 24148 KB Output is correct
14 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 29 ms 5776 KB Output is correct
5 Correct 118 ms 22060 KB Output is correct
6 Correct 130 ms 22084 KB Output is correct
7 Correct 120 ms 22100 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 30 ms 6228 KB Output is correct
10 Correct 118 ms 24148 KB Output is correct
11 Correct 119 ms 24148 KB Output is correct
12 Correct 133 ms 24144 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 32 ms 6236 KB Output is correct
17 Correct 124 ms 24092 KB Output is correct
18 Correct 122 ms 24108 KB Output is correct
19 Correct 118 ms 24000 KB Output is correct
20 Correct 120 ms 24144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 111 ms 22056 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1136 KB Output is correct
13 Correct 115 ms 22216 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 72 ms 12308 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 5724 KB Output is correct
21 Correct 122 ms 22096 KB Output is correct
22 Correct 112 ms 22100 KB Output is correct
23 Correct 119 ms 22100 KB Output is correct
24 Correct 121 ms 22100 KB Output is correct
25 Correct 53 ms 12112 KB Output is correct
26 Correct 48 ms 12116 KB Output is correct
27 Correct 123 ms 22128 KB Output is correct
28 Correct 112 ms 22080 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1116 KB Output is correct
37 Correct 119 ms 22100 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1408 KB Output is correct
41 Correct 123 ms 24148 KB Output is correct
42 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1144 KB Output is correct
7 Correct 111 ms 22056 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1136 KB Output is correct
13 Correct 115 ms 22216 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 72 ms 12308 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 5724 KB Output is correct
21 Correct 122 ms 22096 KB Output is correct
22 Correct 112 ms 22100 KB Output is correct
23 Correct 119 ms 22100 KB Output is correct
24 Correct 121 ms 22100 KB Output is correct
25 Correct 53 ms 12112 KB Output is correct
26 Correct 48 ms 12116 KB Output is correct
27 Correct 123 ms 22128 KB Output is correct
28 Correct 112 ms 22080 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1116 KB Output is correct
37 Correct 119 ms 22100 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1408 KB Output is correct
41 Correct 123 ms 24148 KB Output is correct
42 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
43 Halted 0 ms 0 KB -