답안 #693118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
693118 2023-02-02T11:46:59 Z NemanjaSo2005 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
211 ms 24100 KB
#include<bits/stdc++.h>
#include "supertrees.h"
#define ll long long
using namespace std;
int kol[1005][1005],N,rod[1005],vel[1005],boja[1005];
vector<int> tclik;
bool stavio[1005];
int getparent(int koji){
   if(rod[koji]==koji)
      return koji;
   rod[koji]=getparent(rod[koji]);
   return rod[koji];
}
void spoj(int a,int b){
   a=getparent(a);
   b=getparent(b);
   if(vel[a]<vel[b])
      rod[a]=b;
   else{
      vel[a]=max(vel[a],vel[b]+1);
      rod[b]=a;
   }
   return;
}
vector<int> graf[1005];
void dfs(int gde,int stavi){
   boja[gde]=stavi;
   for(int i=0;i<graf[gde].size();i++)
      if(boja[graf[gde][i]]==0)
         dfs(graf[gde][i],stavi);
   return;
}
int construct(vector<vector<int>> p){
   N=p.size();
   for(int i=1;i<=N;i++){
      rod[i]=i;
      vel[i]=1;
   }
   for(int i=1;i<=N;i++)
      for(int j=1;j<=N;j++){
         kol[i][j]=p[i-1][j-1];
         if(kol[i][j]==3)
            return 0;
      }

   for(int i=1;i<=N;i++){
      int tren=i;
      if(stavio[tren])
         continue;
      if(graf[tren].size()!=0)
        continue;
      tclik.clear();
      tclik.push_back(tren);
      for(int j=1;j<=N;j++){
         if(j==i)
            continue;
         if(stavio[j])
            continue;
         bool moze=true;
         for(int k=0;k<tclik.size();k++)
            if(kol[j][tclik[k]]!=2)
               moze=false;
         if(moze)
            tclik.push_back(j);
      }
      if(tclik.size()<=2)
         continue;
      tclik.push_back(tren);
      for(int j=0;j<tclik.size()-1;j++){
         spoj(tren,tclik[j]);
         graf[tclik[j]].push_back(tclik[j+1]);
         graf[tclik[j+1]].push_back(tclik[j]);
         stavio[tclik[j]]=true;
      }/*
      cout<<"KLIK OD "<<i<<":\n";
      for(int j=0;j<tclik.size();j++)
         cout<<tclik[j]<<" ";
      cout<<endl;*/
      for(int j=0;j<tclik.size()-1;j++){
         int tmp=tclik[j];
         for(int k=1;k<=N;k++){
            if(getparent(k)==getparent(tmp))
               continue;
            if(kol[tmp][k]!=1)
               continue;
            if(stavio[k])
               return 0;
            spoj(tmp,k);
            graf[tmp].push_back(k);
            graf[k].push_back(tmp);
         }
      }
   }

   for(int i=1;i<=N;i++){
      for(int j=1;j<=N;j++)
         if(kol[i][j]==1 and getparent(i)!=getparent(j)){
            spoj(i,j);
            graf[i].push_back(j);
            graf[j].push_back(i);
         }
   }

   for(int i=1;i<=N;i++)
      if(boja[i]==0)
         dfs(i,i);
   for(int i=1;i<=N;i++)
      for(int j=1;j<=N;j++){
         if(kol[i][j]!=0 and boja[i]!=boja[j]){
            return 0;
         }
         if(kol[i][j]==0 and boja[i]==boja[j]){
            return 0;
         }
      }
   for(int i=0;i<p.size();i++)
      for(int j=0;j<p.size();j++)
         p[i][j]=0;
   for(int i=1;i<=N;i++)
      for(int j=0;j<graf[i].size();j++)
         p[i-1][graf[i][j]-1]=1;
   build(p);
   return 1;
}

Compilation message

supertrees.cpp: In function 'void dfs(int, int)':
supertrees.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    for(int i=0;i<graf[gde].size();i++)
      |                ~^~~~~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |          for(int k=0;k<tclik.size();k++)
      |                      ~^~~~~~~~~~~~~
supertrees.cpp:69:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |       for(int j=0;j<tclik.size()-1;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 j=0;j<tclik.size()-1;j++){
      |                   ~^~~~~~~~~~~~~~~
supertrees.cpp:116:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |    for(int i=0;i<p.size();i++)
      |                ~^~~~~~~~~
supertrees.cpp:117:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |       for(int j=0;j<p.size();j++)
      |                   ~^~~~~~~~~
supertrees.cpp:120:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |       for(int j=0;j<graf[i].size();j++)
      |                   ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 9 ms 1748 KB Output is correct
7 Correct 211 ms 22104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 9 ms 1748 KB Output is correct
7 Correct 211 ms 22104 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 11 ms 1840 KB Output is correct
13 Correct 176 ms 21996 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 1364 KB Output is correct
17 Correct 93 ms 12088 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 49 ms 6688 KB Output is correct
21 Correct 177 ms 22056 KB Output is correct
22 Correct 178 ms 22092 KB Output is correct
23 Correct 188 ms 22104 KB Output is correct
24 Correct 174 ms 21964 KB Output is correct
25 Correct 105 ms 12200 KB Output is correct
26 Correct 115 ms 12072 KB Output is correct
27 Correct 196 ms 22036 KB Output is correct
28 Correct 177 ms 21964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 8 ms 1748 KB Output is correct
9 Correct 177 ms 22028 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 8 ms 1876 KB Output is correct
13 Correct 172 ms 22064 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 1364 KB Output is correct
17 Correct 81 ms 12088 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 47 ms 6720 KB Output is correct
22 Correct 189 ms 22068 KB Output is correct
23 Correct 177 ms 22056 KB Output is correct
24 Correct 211 ms 22052 KB Output is correct
25 Correct 85 ms 12068 KB Output is correct
26 Correct 85 ms 12068 KB Output is correct
27 Correct 170 ms 22068 KB Output is correct
28 Correct 178 ms 22068 KB Output is correct
29 Correct 72 ms 12148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 43 ms 6852 KB Output is correct
5 Correct 171 ms 22092 KB Output is correct
6 Correct 171 ms 22036 KB Output is correct
7 Correct 186 ms 22116 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 46 ms 6728 KB Output is correct
10 Correct 179 ms 22136 KB Output is correct
11 Correct 174 ms 22092 KB Output is correct
12 Correct 194 ms 22100 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 44 ms 6788 KB Output is correct
17 Correct 179 ms 23968 KB Output is correct
18 Correct 172 ms 24060 KB Output is correct
19 Correct 178 ms 24100 KB Output is correct
20 Correct 192 ms 24012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 9 ms 1748 KB Output is correct
7 Correct 211 ms 22104 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 11 ms 1840 KB Output is correct
13 Correct 176 ms 21996 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 1364 KB Output is correct
17 Correct 93 ms 12088 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 49 ms 6688 KB Output is correct
21 Correct 177 ms 22056 KB Output is correct
22 Correct 178 ms 22092 KB Output is correct
23 Correct 188 ms 22104 KB Output is correct
24 Correct 174 ms 21964 KB Output is correct
25 Correct 105 ms 12200 KB Output is correct
26 Correct 115 ms 12072 KB Output is correct
27 Correct 196 ms 22036 KB Output is correct
28 Correct 177 ms 21964 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 8 ms 1748 KB Output is correct
37 Correct 177 ms 22028 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 8 ms 1876 KB Output is correct
41 Correct 172 ms 22064 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 4 ms 1364 KB Output is correct
45 Correct 81 ms 12088 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 47 ms 6720 KB Output is correct
50 Correct 189 ms 22068 KB Output is correct
51 Correct 177 ms 22056 KB Output is correct
52 Correct 211 ms 22052 KB Output is correct
53 Correct 85 ms 12068 KB Output is correct
54 Correct 85 ms 12068 KB Output is correct
55 Correct 170 ms 22068 KB Output is correct
56 Correct 178 ms 22068 KB Output is correct
57 Correct 72 ms 12148 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 5 ms 1416 KB Output is correct
61 Correct 80 ms 12200 KB Output is correct
62 Correct 0 ms 340 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
65 Correct 46 ms 6716 KB Output is correct
66 Correct 80 ms 14108 KB Output is correct
67 Correct 75 ms 14112 KB Output is correct
68 Correct 76 ms 14120 KB Output is correct
69 Correct 76 ms 14116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 9 ms 1748 KB Output is correct
7 Correct 211 ms 22104 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 11 ms 1840 KB Output is correct
13 Correct 176 ms 21996 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 1364 KB Output is correct
17 Correct 93 ms 12088 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 49 ms 6688 KB Output is correct
21 Correct 177 ms 22056 KB Output is correct
22 Correct 178 ms 22092 KB Output is correct
23 Correct 188 ms 22104 KB Output is correct
24 Correct 174 ms 21964 KB Output is correct
25 Correct 105 ms 12200 KB Output is correct
26 Correct 115 ms 12072 KB Output is correct
27 Correct 196 ms 22036 KB Output is correct
28 Correct 177 ms 21964 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 8 ms 1748 KB Output is correct
37 Correct 177 ms 22028 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 8 ms 1876 KB Output is correct
41 Correct 172 ms 22064 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 4 ms 1364 KB Output is correct
45 Correct 81 ms 12088 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 47 ms 6720 KB Output is correct
50 Correct 189 ms 22068 KB Output is correct
51 Correct 177 ms 22056 KB Output is correct
52 Correct 211 ms 22052 KB Output is correct
53 Correct 85 ms 12068 KB Output is correct
54 Correct 85 ms 12068 KB Output is correct
55 Correct 170 ms 22068 KB Output is correct
56 Correct 178 ms 22068 KB Output is correct
57 Correct 72 ms 12148 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 43 ms 6852 KB Output is correct
62 Correct 171 ms 22092 KB Output is correct
63 Correct 171 ms 22036 KB Output is correct
64 Correct 186 ms 22116 KB Output is correct
65 Correct 0 ms 340 KB Output is correct
66 Correct 46 ms 6728 KB Output is correct
67 Correct 179 ms 22136 KB Output is correct
68 Correct 174 ms 22092 KB Output is correct
69 Correct 194 ms 22100 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 44 ms 6788 KB Output is correct
74 Correct 179 ms 23968 KB Output is correct
75 Correct 172 ms 24060 KB Output is correct
76 Correct 178 ms 24100 KB Output is correct
77 Correct 192 ms 24012 KB Output is correct
78 Correct 0 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 5 ms 1416 KB Output is correct
81 Correct 80 ms 12200 KB Output is correct
82 Correct 0 ms 340 KB Output is correct
83 Correct 0 ms 340 KB Output is correct
84 Correct 0 ms 340 KB Output is correct
85 Correct 46 ms 6716 KB Output is correct
86 Correct 80 ms 14108 KB Output is correct
87 Correct 75 ms 14112 KB Output is correct
88 Correct 76 ms 14120 KB Output is correct
89 Correct 76 ms 14116 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 4 ms 724 KB Output is correct
93 Correct 69 ms 10188 KB Output is correct
94 Correct 0 ms 336 KB Output is correct
95 Correct 1 ms 344 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 18 ms 2900 KB Output is correct
98 Correct 80 ms 10400 KB Output is correct
99 Correct 68 ms 10664 KB Output is correct
100 Correct 70 ms 10392 KB Output is correct
101 Correct 68 ms 11428 KB Output is correct
102 Correct 70 ms 10136 KB Output is correct
103 Correct 77 ms 10140 KB Output is correct
104 Correct 65 ms 10144 KB Output is correct
105 Correct 72 ms 10144 KB Output is correct