Submission #637312

# Submission time Handle Problem Language Result Execution time Memory
637312 2022-09-01T10:17:48 Z fadi57 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
422 ms 24560 KB
#include "supertrees.h"
#include <vector>
//#include "grader.cpp"
#include<bits/stdc++.h>
using namespace std;
const int mx=1e5+5;
int par[mx],par2[mx];std::vector<std::vector<int>> answer;	int ok=1;
int n;
void init(int n){
  for(int i=0;i<=n;i++){
    par[i]=i;
    par2[i]=i;
  }
 
}
int fin(int a){
  if(par[a]==a){
    return a;
  }else{
    return par[a]=fin(par[a]);
  }
 
}
int fin2(int a){
  if(par2[a]==a){
    return a;
  }else{
    return par2[a]=fin2(par2[a]);
  }
 
}
int uni(int a,int b){
 
  a=fin(a);  b=fin(b);
  if(a==b){return 1;}
  par[a]=b;
return 0;
 
 
 }
 int uni2(int a,int b){
 
  a=fin2(a);  b=fin2(b);
  if(a==b){return 1;}
  par2[a]=b;
   return 0;
  }
 int conect(int x){
 
    vector<int>v,nodes[mx];
 
  //  cout<<"TEST "<<x<<endl;
   for(int i=0;i<n;i++){
      if(fin(i)==x){
            int y=fin2(i);
         //  cout<<i<<"  "<<y<<endl;;
        v.push_back(i);
      }
 
   }
 
   set<int>tree;
   for(int i=0;i<v.size();i++){
     // tree.insert(fin2(v[i]));
      int x=fin2(v[i]);
      nodes[x].push_back(v[i]);
 
 
   }
   vector<int>heads;
   for(int i=0;i<n;i++){
      if(nodes[i].size()!=0){
        heads.push_back(i);
        for(int j=0;j<nodes[i].size()-1;j++){
                int me= nodes[i][j];int nxt=nodes[i][j+1];
            answer[me][nxt]=answer[nxt][me]=1;
 
        }
      }
 
   }
 //  cout<<" hello "<<heads.size()<<endl;
   if(heads.size()==2){ok=0;return 0;}
   if(heads.size()==1){return 0;}
   for(int i=0;i<heads.size();i++){
     //   cout<<" helo "<<heads[i]<<endl;
    int me=heads[i];int nxt=heads[(i+1)%heads.size()];
    answer[me][nxt]=1; answer[nxt][me]=1;
   }
   return 0;
 
  }
int construct(vector<vector<int>> p) {
	 n = p.size();
   init(n);
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
           if(p[i][j]) uni(i,j);
          if(p[i][j]==3){ok=0;}
           if(p[i][j]==1){uni2(i,j);}
        }
	}
 
		for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
          if(p[i][j]==0&&fin(i)==fin(j))ok=0;
        }
	}
	if(ok==0){return 0;}
	vector<int>comp[n+5];
     for(int i=0;i<n;i++){
        conect(i);
        if(ok==0){return 0;}
 
    }
    for(int i=0;i<n;i++){
         for(int j=0;j<n;j++){
         //   cout<<answer[i][j]<<" ";
         }
       //  cout<<endl;
    }
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int conect(int)':
supertrees.cpp:55:17: warning: unused variable 'y' [-Wunused-variable]
   55 |             int y=fin2(i);
      |                 ^
supertrees.cpp:63:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |    for(int i=0;i<v.size();i++){
      |                ~^~~~~~~~~
supertrees.cpp:74:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for(int j=0;j<nodes[i].size()-1;j++){
      |                     ~^~~~~~~~~~~~~~~~~~
supertrees.cpp:85:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |    for(int i=0;i<heads.size();i++){
      |                ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 53 ms 3532 KB Output is correct
7 Correct 395 ms 24348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 53 ms 3532 KB Output is correct
7 Correct 395 ms 24348 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 55 ms 3516 KB Output is correct
13 Correct 388 ms 24396 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 89 ms 12176 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 152 ms 8140 KB Output is correct
21 Correct 378 ms 24348 KB Output is correct
22 Correct 400 ms 24396 KB Output is correct
23 Correct 402 ms 24392 KB Output is correct
24 Correct 379 ms 24376 KB Output is correct
25 Correct 76 ms 12044 KB Output is correct
26 Correct 69 ms 12048 KB Output is correct
27 Correct 385 ms 24372 KB Output is correct
28 Correct 375 ms 24368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 56 ms 3520 KB Output is correct
9 Correct 374 ms 24320 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 55 ms 3512 KB Output is correct
13 Correct 382 ms 24464 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 86 ms 12056 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 152 ms 8080 KB Output is correct
22 Correct 378 ms 24396 KB Output is correct
23 Correct 380 ms 24340 KB Output is correct
24 Correct 422 ms 24396 KB Output is correct
25 Correct 276 ms 14540 KB Output is correct
26 Correct 70 ms 12048 KB Output is correct
27 Correct 384 ms 24400 KB Output is correct
28 Correct 399 ms 24396 KB Output is correct
29 Correct 283 ms 14540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 164 ms 8072 KB Output is correct
5 Correct 404 ms 24364 KB Output is correct
6 Correct 385 ms 24560 KB Output is correct
7 Correct 407 ms 24332 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 152 ms 8084 KB Output is correct
10 Correct 393 ms 24476 KB Output is correct
11 Correct 401 ms 24396 KB Output is correct
12 Correct 394 ms 24476 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 5 ms 2644 KB Output is correct
15 Correct 4 ms 2644 KB Output is correct
16 Correct 162 ms 8076 KB Output is correct
17 Correct 406 ms 24448 KB Output is correct
18 Correct 384 ms 24344 KB Output is correct
19 Correct 401 ms 24500 KB Output is correct
20 Correct 374 ms 24332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 53 ms 3532 KB Output is correct
7 Correct 395 ms 24348 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 55 ms 3516 KB Output is correct
13 Correct 388 ms 24396 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 89 ms 12176 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 152 ms 8140 KB Output is correct
21 Correct 378 ms 24348 KB Output is correct
22 Correct 400 ms 24396 KB Output is correct
23 Correct 402 ms 24392 KB Output is correct
24 Correct 379 ms 24376 KB Output is correct
25 Correct 76 ms 12044 KB Output is correct
26 Correct 69 ms 12048 KB Output is correct
27 Correct 385 ms 24372 KB Output is correct
28 Correct 375 ms 24368 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 2 ms 2644 KB Output is correct
35 Correct 3 ms 2644 KB Output is correct
36 Correct 56 ms 3520 KB Output is correct
37 Correct 374 ms 24320 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 3 ms 2644 KB Output is correct
40 Correct 55 ms 3512 KB Output is correct
41 Correct 382 ms 24464 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 86 ms 12056 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 152 ms 8080 KB Output is correct
50 Correct 378 ms 24396 KB Output is correct
51 Correct 380 ms 24340 KB Output is correct
52 Correct 422 ms 24396 KB Output is correct
53 Correct 276 ms 14540 KB Output is correct
54 Correct 70 ms 12048 KB Output is correct
55 Correct 384 ms 24400 KB Output is correct
56 Correct 399 ms 24396 KB Output is correct
57 Correct 283 ms 14540 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 292 KB Output is correct
60 Correct 4 ms 724 KB Output is correct
61 Correct 87 ms 12056 KB Output is correct
62 Correct 2 ms 2644 KB Output is correct
63 Correct 4 ms 2596 KB Output is correct
64 Correct 4 ms 2644 KB Output is correct
65 Correct 147 ms 8084 KB Output is correct
66 Correct 74 ms 12048 KB Output is correct
67 Correct 78 ms 12180 KB Output is correct
68 Correct 70 ms 12060 KB Output is correct
69 Correct 176 ms 14412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 53 ms 3532 KB Output is correct
7 Correct 395 ms 24348 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 55 ms 3516 KB Output is correct
13 Correct 388 ms 24396 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 89 ms 12176 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 152 ms 8140 KB Output is correct
21 Correct 378 ms 24348 KB Output is correct
22 Correct 400 ms 24396 KB Output is correct
23 Correct 402 ms 24392 KB Output is correct
24 Correct 379 ms 24376 KB Output is correct
25 Correct 76 ms 12044 KB Output is correct
26 Correct 69 ms 12048 KB Output is correct
27 Correct 385 ms 24372 KB Output is correct
28 Correct 375 ms 24368 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 2 ms 2644 KB Output is correct
35 Correct 3 ms 2644 KB Output is correct
36 Correct 56 ms 3520 KB Output is correct
37 Correct 374 ms 24320 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 3 ms 2644 KB Output is correct
40 Correct 55 ms 3512 KB Output is correct
41 Correct 382 ms 24464 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 86 ms 12056 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 152 ms 8080 KB Output is correct
50 Correct 378 ms 24396 KB Output is correct
51 Correct 380 ms 24340 KB Output is correct
52 Correct 422 ms 24396 KB Output is correct
53 Correct 276 ms 14540 KB Output is correct
54 Correct 70 ms 12048 KB Output is correct
55 Correct 384 ms 24400 KB Output is correct
56 Correct 399 ms 24396 KB Output is correct
57 Correct 283 ms 14540 KB Output is correct
58 Correct 2 ms 2644 KB Output is correct
59 Correct 2 ms 2644 KB Output is correct
60 Correct 4 ms 2644 KB Output is correct
61 Correct 164 ms 8072 KB Output is correct
62 Correct 404 ms 24364 KB Output is correct
63 Correct 385 ms 24560 KB Output is correct
64 Correct 407 ms 24332 KB Output is correct
65 Correct 2 ms 2644 KB Output is correct
66 Correct 152 ms 8084 KB Output is correct
67 Correct 393 ms 24476 KB Output is correct
68 Correct 401 ms 24396 KB Output is correct
69 Correct 394 ms 24476 KB Output is correct
70 Correct 2 ms 2644 KB Output is correct
71 Correct 5 ms 2644 KB Output is correct
72 Correct 4 ms 2644 KB Output is correct
73 Correct 162 ms 8076 KB Output is correct
74 Correct 406 ms 24448 KB Output is correct
75 Correct 384 ms 24344 KB Output is correct
76 Correct 401 ms 24500 KB Output is correct
77 Correct 374 ms 24332 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 292 KB Output is correct
80 Correct 4 ms 724 KB Output is correct
81 Correct 87 ms 12056 KB Output is correct
82 Correct 2 ms 2644 KB Output is correct
83 Correct 4 ms 2596 KB Output is correct
84 Correct 4 ms 2644 KB Output is correct
85 Correct 147 ms 8084 KB Output is correct
86 Correct 74 ms 12048 KB Output is correct
87 Correct 78 ms 12180 KB Output is correct
88 Correct 70 ms 12060 KB Output is correct
89 Correct 176 ms 14412 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 4 ms 724 KB Output is correct
93 Correct 94 ms 12180 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 18 ms 3716 KB Output is correct
98 Correct 73 ms 14004 KB Output is correct
99 Correct 77 ms 14028 KB Output is correct
100 Correct 70 ms 14028 KB Output is correct
101 Correct 72 ms 14080 KB Output is correct
102 Correct 74 ms 14076 KB Output is correct
103 Correct 76 ms 14120 KB Output is correct
104 Correct 80 ms 14028 KB Output is correct
105 Correct 88 ms 14092 KB Output is correct