Submission #1076815

# Submission time Handle Problem Language Result Execution time Memory
1076815 2024-08-26T16:52:07 Z Hectorungo_18 Connecting Supertrees (IOI20_supertrees) C++14
96 / 100
137 ms 24188 KB
#include "supertrees.h"
#include <vector>
#include<bits/stdc++.h>
 
using namespace std;
 
 
 
const int N = 1e3+7;
int p[N];
int sz[N];
 
 
int pa(int u){
	p[u]=(p[u] == u ? u : pa(p[u]));
	return p[u];
}
 
bool sm(int u, int v){
	return pa(u) == pa(v);
}
 
void un(int u, int v){
	if(sm(u, v)) return;
	u = pa(u);
	v = pa(v);
	if(sz[v] > sz[u]) swap(u, v);
	sz[u]+=sz[v];
	p[v]=u;
}
 
int construct(vector<vector<int>> v) {
	int n = v.size();
	for(int i = 0; i <= n; i++){
		p[i]=i;
		sz[i]=1;
	}
	for(int i = 0; i < n; i++){
        bool ch = 0;
        if(pa(i)==i) ch = 1;
		for(int j = i+1; j < n; j++){
			if(ch){
                if(v[i][j] == 0) continue;
                if(pa(j) == j){
                    un(i, j);
                }
                else return 0;
			}
            else{
                if(v[i][j] == 0){
                  if(pa(i) == pa(j)) return 0;
                }
              else if(pa(i) != pa(j)) return 0;
              	
            }
		}
	}
 
    map<int, int> m;
    for(int i = 0; i < n; i++){
        vector<int> a(4, 0);
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            a[v[i][j]]++;
        }
        if(a[1] > 0) m[i]=1;
        else if(a[2] > 0) m[i]=2;
        else if(a[3] > 0) m[i]=3;
        else m[i]=0;
    }
 
    vector<vector<int>> ans(n, vector<int> (n, 0));
    vector<int> sp(n);
    for(int i = 0; i < n; i++){
        sp[i]=pa(i);
    }
    for(int i = 0; i < n; i++){
        p[i]=i;
        sz[i]=i;
    }
    for(int i = 0; i < n; i++){
        if(sp[i] != i) continue;
        vector<int> w;
        for(int j = 0; j < n; j++){
            if(sp[j] == i) w.push_back(j);
        }
        vector<int> dd;
        for(int j = 0; j < w.size(); j++){
            int r = w[j];
 
            for(int k = 0; k < n; k++){
                if(k == r) continue;
                if(v[r][k] != 1) continue;
                if(pa(r) == pa(k)) continue;
                if(pa(r) == r){
                    un(r, k);
                }
                else{
                    if(pa(k) == k){
                        un(r, k);
                    }
                    else return 0;
                }
            }
        }
        for(int j = 0; j < w.size(); j++){
            if(w[j] == pa(w[j])) dd.push_back(w[j]);
        }
        if(dd.size() == 2) return 0;
        for(int j = 1; j < dd.size(); j++){
            ans[dd[j]][dd[j-1]] = 1;
            ans[dd[j-1]][dd[j]] = 1;
        }
        if(dd.size() > 2){
            ans[dd[0]][dd.back()] = 1;
            ans[dd.back()][dd[0]] = 1;
        }
        vector<vector<int>> adj(n);
        for(int i = 0; i < w.size(); i++){
            int r = w[i];
            adj[pa(r)].push_back(r);
        }
        for(int i = 0; i < n; i++){
            for(int j = 1; j < adj[i].size(); j++){
                ans[adj[i][j]][adj[i][j-1]] = 1;
                ans[adj[i][j-1]][adj[i][j]] = 1;
            }
        }
    }
    
    build(ans);
 
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:88:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for(int j = 0; j < w.size(); j++){
      |                        ~~^~~~~~~~~~
supertrees.cpp:106:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for(int j = 0; j < w.size(); j++){
      |                        ~~^~~~~~~~~~
supertrees.cpp:110:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |         for(int j = 1; j < dd.size(); j++){
      |                        ~~^~~~~~~~~~~
supertrees.cpp:119:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |         for(int i = 0; i < w.size(); i++){
      |                        ~~^~~~~~~~~~
supertrees.cpp:124:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |             for(int j = 1; j < adj[i].size(); j++){
      |                            ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 121 ms 22096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 121 ms 22096 KB Output is correct
8 Correct 0 ms 348 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 344 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 123 ms 22044 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 56 ms 8204 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 31 ms 5728 KB Output is correct
21 Correct 128 ms 22100 KB Output is correct
22 Correct 117 ms 22296 KB Output is correct
23 Correct 125 ms 22044 KB Output is correct
24 Correct 132 ms 22044 KB Output is correct
25 Correct 50 ms 8276 KB Output is correct
26 Correct 58 ms 8204 KB Output is correct
27 Correct 126 ms 22100 KB Output is correct
28 Correct 117 ms 22100 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 129 ms 22152 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 118 ms 22024 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 55 ms 8220 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 32 ms 5716 KB Output is correct
22 Correct 121 ms 24144 KB Output is correct
23 Correct 125 ms 24148 KB Output is correct
24 Correct 123 ms 24144 KB Output is correct
25 Correct 57 ms 14112 KB Output is correct
26 Correct 51 ms 10320 KB Output is correct
27 Correct 119 ms 24148 KB Output is correct
28 Correct 137 ms 24064 KB Output is correct
29 Correct 60 ms 14160 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 31 ms 5724 KB Output is correct
5 Correct 120 ms 22096 KB Output is correct
6 Correct 118 ms 22100 KB Output is correct
7 Correct 124 ms 22044 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 29 ms 5920 KB Output is correct
10 Correct 128 ms 24072 KB Output is correct
11 Correct 115 ms 24144 KB Output is correct
12 Correct 123 ms 24148 KB Output is correct
13 Correct 0 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 30 ms 6236 KB Output is correct
17 Correct 123 ms 23944 KB Output is correct
18 Correct 115 ms 24148 KB Output is correct
19 Correct 122 ms 24188 KB Output is correct
20 Correct 120 ms 24148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 121 ms 22096 KB Output is correct
8 Correct 0 ms 348 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 344 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 123 ms 22044 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 56 ms 8204 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 31 ms 5728 KB Output is correct
21 Correct 128 ms 22100 KB Output is correct
22 Correct 117 ms 22296 KB Output is correct
23 Correct 125 ms 22044 KB Output is correct
24 Correct 132 ms 22044 KB Output is correct
25 Correct 50 ms 8276 KB Output is correct
26 Correct 58 ms 8204 KB Output is correct
27 Correct 126 ms 22100 KB Output is correct
28 Correct 117 ms 22100 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 129 ms 22152 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 5 ms 1116 KB Output is correct
41 Correct 118 ms 22024 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 55 ms 8220 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 32 ms 5716 KB Output is correct
50 Correct 121 ms 24144 KB Output is correct
51 Correct 125 ms 24148 KB Output is correct
52 Correct 123 ms 24144 KB Output is correct
53 Correct 57 ms 14112 KB Output is correct
54 Correct 51 ms 10320 KB Output is correct
55 Correct 119 ms 24148 KB Output is correct
56 Correct 137 ms 24064 KB Output is correct
57 Correct 60 ms 14160 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 604 KB Output is correct
61 Correct 52 ms 10252 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 34 ms 6280 KB Output is correct
66 Correct 50 ms 10064 KB Output is correct
67 Correct 50 ms 10068 KB Output is correct
68 Correct 52 ms 10452 KB Output is correct
69 Correct 49 ms 14256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 121 ms 22096 KB Output is correct
8 Correct 0 ms 348 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 344 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 123 ms 22044 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 56 ms 8204 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 31 ms 5728 KB Output is correct
21 Correct 128 ms 22100 KB Output is correct
22 Correct 117 ms 22296 KB Output is correct
23 Correct 125 ms 22044 KB Output is correct
24 Correct 132 ms 22044 KB Output is correct
25 Correct 50 ms 8276 KB Output is correct
26 Correct 58 ms 8204 KB Output is correct
27 Correct 126 ms 22100 KB Output is correct
28 Correct 117 ms 22100 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 129 ms 22152 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 5 ms 1116 KB Output is correct
41 Correct 118 ms 22024 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 55 ms 8220 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 32 ms 5716 KB Output is correct
50 Correct 121 ms 24144 KB Output is correct
51 Correct 125 ms 24148 KB Output is correct
52 Correct 123 ms 24144 KB Output is correct
53 Correct 57 ms 14112 KB Output is correct
54 Correct 51 ms 10320 KB Output is correct
55 Correct 119 ms 24148 KB Output is correct
56 Correct 137 ms 24064 KB Output is correct
57 Correct 60 ms 14160 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 31 ms 5724 KB Output is correct
62 Correct 120 ms 22096 KB Output is correct
63 Correct 118 ms 22100 KB Output is correct
64 Correct 124 ms 22044 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 29 ms 5920 KB Output is correct
67 Correct 128 ms 24072 KB Output is correct
68 Correct 115 ms 24144 KB Output is correct
69 Correct 123 ms 24148 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 30 ms 6236 KB Output is correct
74 Correct 123 ms 23944 KB Output is correct
75 Correct 115 ms 24148 KB Output is correct
76 Correct 122 ms 24188 KB Output is correct
77 Correct 120 ms 24148 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 604 KB Output is correct
81 Correct 52 ms 10252 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 1 ms 348 KB Output is correct
85 Correct 34 ms 6280 KB Output is correct
86 Correct 50 ms 10064 KB Output is correct
87 Correct 50 ms 10068 KB Output is correct
88 Correct 52 ms 10452 KB Output is correct
89 Correct 49 ms 14256 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 3 ms 684 KB Output is correct
93 Correct 50 ms 10064 KB Output is correct
94 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -