답안 #316365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
316365 2020-10-26T07:14:46 Z demetre 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
279 ms 29432 KB
#include "supertrees.h"
#include <vector>
# include <bits/stdc++.h>
using namespace std;
 
long long par[300005],a,bb,n,fix[300005],w1,w2,sh1,fix1[300005],wv,par1[300005];
long long pa,sh;
//std::vector <std::vector <int> >  ans;
vector <long long> v[300005],v1,v2;
int get_col(int a)
{
    if (par[a]==a) return a;
    par[a]=get_col(par[a]);
    return par[a];
}
void col(int a, int b)
{
    a=get_col(a);
    b=get_col(b);
    par[a]=b;
}
int get_col1(int a)
{
    if (par1[a]==a) return a;
    par1[a]=get_col1(par1[a]);
    return par1[a];
}
void col1(int a, int b)
{
    a=get_col1(a);
    b=get_col1(b);
    par1[a]=b;
}
int construct(vector <vector <int> > p)
{
     int n=p.size();
     for (int i=0; i<n; i++)
   {
          par[i]=i;
     }
     for (int i=0; i<n; i++)
     {
          for (int j=0; j<n; 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]) col(i,j);
          }
     }
     for (int i=0; i<n; i++)
     {
         for (int j=0; j<n; j++)
         {
             if (get_col(i)==get_col(j) && !p[i][j]) return 0;
         }
     }
     
     for (int i=0; i<n;i++)
     {
          v[get_col(i)].push_back(i);
     }
     for (int i=0; i<n; i++)
     {
        if (!fix[get_col(i)])
        {
            v1.push_back(get_col(i)); 
            fix[get_col(i)]=1;              
        }
     }
	vector < vector < int > > ans(n, vector < int >(n, 0));
	for (int i=0; i<n; i++)
	{
		par1[i]=i;
	}
     for (int i=0; i<v1.size(); i++)
     {
     	pa=v1[i];
     	for(int j=0;j<v[pa].size(); j++)
     	{
     		for (int j1=j+1; j1<v[pa].size(); j1++)
     		{
     			w1=v[pa][j];
     			w2=v[pa][j1];
     			if (p[w1][w2]==1)
     			col1(w1,w2);
			}
		}
	}
	for (int i=0; i<v1.size() ;i++)
	{
		pa=v1[i];
		for(int j=0; j<v[pa].size(); j++)
		{
			sh=get_col1(v[pa][j]);
			sh1=v[pa][j];
			if (sh!=sh1)
			{
				ans[sh][sh1]=1;
				ans[sh1][sh]=1;
			}
		}
	}
	/*
4 
1 1 2 2 
1 1 2 2
2 2 1 2
2 2 2 1
	*/
    for (int i=0; i<v1.size(); i++)
    {
    		pa=v1[i];
    		for (int j=0; j<v[pa].size(); j++)
    		{
    			for (int j1=0; j1<v[pa].size(); j1++)
			{
				w1=v[pa][j];
     			w2=v[pa][j1];
     			if (p[w1][w2]==2)
     			{
     				if (get_col1(w1)==get_col1(w2)) return 0;
				}
			}
		}
    }
    for (int i=0; i<v1.size(); i++)
    {
    		pa=v1[i];
    		v2.clear();
    		for (int j=0; j<v[pa].size(); j++)
    		{
    			wv=v[pa][j];
    			if (!fix1[get_col1(wv)])
			{
				fix1[get_col1(wv)]=1;
				v2.push_back(get_col1(wv));    	
			}
		}
		if (v2.size()==2)
		{
			return 0;
		}
		v2.push_back(v2[0]);
		for (int i=1; i<v2.size(); i++)
		{
			w1=v2[i];
			w2=v2[i-1];
			if (w1!=w2)
			{
			
			ans[w1][w2]=1;
			ans[w2][w1]=1;
			}
		}
    }
    
     build(ans);
  return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:81:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |      for (int i=0; i<v1.size(); i++)
      |                    ~^~~~~~~~~~
supertrees.cpp:84:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |       for(int j=0;j<v[pa].size(); j++)
      |                   ~^~~~~~~~~~~~~
supertrees.cpp:86:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |        for (int j1=j+1; j1<v[pa].size(); j1++)
      |                         ~~^~~~~~~~~~~~~
supertrees.cpp:95:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |  for (int i=0; i<v1.size() ;i++)
      |                ~^~~~~~~~~~
supertrees.cpp:98:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |   for(int j=0; j<v[pa].size(); j++)
      |                ~^~~~~~~~~~~~~
supertrees.cpp:116:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |     for (int i=0; i<v1.size(); i++)
      |                   ~^~~~~~~~~~
supertrees.cpp:119:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |       for (int j=0; j<v[pa].size(); j++)
      |                     ~^~~~~~~~~~~~~
supertrees.cpp:121:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |        for (int j1=0; j1<v[pa].size(); j1++)
      |                       ~~^~~~~~~~~~~~~
supertrees.cpp:132:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |     for (int i=0; i<v1.size(); i++)
      |                   ~^~~~~~~~~~
supertrees.cpp:136:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |       for (int j=0; j<v[pa].size(); j++)
      |                     ~^~~~~~~~~~~~~
supertrees.cpp:150:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |   for (int i=1; i<v2.size(); i++)
      |                 ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 16 ms 8320 KB Output is correct
7 Correct 274 ms 29176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 16 ms 8320 KB Output is correct
7 Correct 274 ms 29176 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 15 ms 8320 KB Output is correct
13 Correct 243 ms 29284 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 6 ms 7336 KB Output is correct
16 Correct 10 ms 7680 KB Output is correct
17 Correct 120 ms 15224 KB Output is correct
18 Correct 5 ms 7424 KB Output is correct
19 Correct 5 ms 7424 KB Output is correct
20 Correct 66 ms 13016 KB Output is correct
21 Correct 252 ms 29176 KB Output is correct
22 Correct 256 ms 29176 KB Output is correct
23 Correct 279 ms 29304 KB Output is correct
24 Correct 248 ms 29412 KB Output is correct
25 Correct 102 ms 15224 KB Output is correct
26 Correct 101 ms 15352 KB Output is correct
27 Correct 278 ms 29340 KB Output is correct
28 Correct 243 ms 29432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 15 ms 8320 KB Output is correct
9 Correct 242 ms 29180 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 16 ms 8320 KB Output is correct
13 Correct 266 ms 29276 KB Output is correct
14 Correct 6 ms 7424 KB Output is correct
15 Correct 5 ms 7424 KB Output is correct
16 Correct 10 ms 7680 KB Output is correct
17 Correct 120 ms 15336 KB Output is correct
18 Correct 6 ms 7424 KB Output is correct
19 Correct 5 ms 7424 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 66 ms 12896 KB Output is correct
22 Correct 252 ms 29304 KB Output is correct
23 Correct 249 ms 29304 KB Output is correct
24 Correct 275 ms 29176 KB Output is correct
25 Correct 103 ms 19320 KB Output is correct
26 Correct 104 ms 15352 KB Output is correct
27 Correct 247 ms 29176 KB Output is correct
28 Correct 278 ms 29176 KB Output is correct
29 Correct 105 ms 19320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 66 ms 12920 KB Output is correct
5 Correct 255 ms 29176 KB Output is correct
6 Correct 254 ms 29200 KB Output is correct
7 Correct 275 ms 29156 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 68 ms 12920 KB Output is correct
10 Correct 254 ms 29260 KB Output is correct
11 Correct 245 ms 29280 KB Output is correct
12 Correct 273 ms 29176 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 5 ms 7424 KB Output is correct
16 Correct 65 ms 12920 KB Output is correct
17 Correct 253 ms 29304 KB Output is correct
18 Correct 249 ms 29176 KB Output is correct
19 Correct 247 ms 29176 KB Output is correct
20 Correct 248 ms 29176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 16 ms 8320 KB Output is correct
7 Correct 274 ms 29176 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 15 ms 8320 KB Output is correct
13 Correct 243 ms 29284 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 6 ms 7336 KB Output is correct
16 Correct 10 ms 7680 KB Output is correct
17 Correct 120 ms 15224 KB Output is correct
18 Correct 5 ms 7424 KB Output is correct
19 Correct 5 ms 7424 KB Output is correct
20 Correct 66 ms 13016 KB Output is correct
21 Correct 252 ms 29176 KB Output is correct
22 Correct 256 ms 29176 KB Output is correct
23 Correct 279 ms 29304 KB Output is correct
24 Correct 248 ms 29412 KB Output is correct
25 Correct 102 ms 15224 KB Output is correct
26 Correct 101 ms 15352 KB Output is correct
27 Correct 278 ms 29340 KB Output is correct
28 Correct 243 ms 29432 KB Output is correct
29 Correct 5 ms 7424 KB Output is correct
30 Correct 5 ms 7424 KB Output is correct
31 Correct 5 ms 7424 KB Output is correct
32 Correct 5 ms 7424 KB Output is correct
33 Correct 5 ms 7424 KB Output is correct
34 Correct 5 ms 7424 KB Output is correct
35 Correct 5 ms 7424 KB Output is correct
36 Correct 15 ms 8320 KB Output is correct
37 Correct 242 ms 29180 KB Output is correct
38 Correct 5 ms 7424 KB Output is correct
39 Correct 5 ms 7424 KB Output is correct
40 Correct 16 ms 8320 KB Output is correct
41 Correct 266 ms 29276 KB Output is correct
42 Correct 6 ms 7424 KB Output is correct
43 Correct 5 ms 7424 KB Output is correct
44 Correct 10 ms 7680 KB Output is correct
45 Correct 120 ms 15336 KB Output is correct
46 Correct 6 ms 7424 KB Output is correct
47 Correct 5 ms 7424 KB Output is correct
48 Correct 5 ms 7424 KB Output is correct
49 Correct 66 ms 12896 KB Output is correct
50 Correct 252 ms 29304 KB Output is correct
51 Correct 249 ms 29304 KB Output is correct
52 Correct 275 ms 29176 KB Output is correct
53 Correct 103 ms 19320 KB Output is correct
54 Correct 104 ms 15352 KB Output is correct
55 Correct 247 ms 29176 KB Output is correct
56 Correct 278 ms 29176 KB Output is correct
57 Correct 105 ms 19320 KB Output is correct
58 Correct 5 ms 7424 KB Output is correct
59 Correct 5 ms 7424 KB Output is correct
60 Correct 10 ms 7680 KB Output is correct
61 Correct 120 ms 15224 KB Output is correct
62 Correct 5 ms 7424 KB Output is correct
63 Correct 5 ms 7424 KB Output is correct
64 Correct 5 ms 7424 KB Output is correct
65 Correct 69 ms 12920 KB Output is correct
66 Correct 105 ms 15228 KB Output is correct
67 Correct 102 ms 15228 KB Output is correct
68 Correct 100 ms 15228 KB Output is correct
69 Correct 106 ms 19320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 16 ms 8320 KB Output is correct
7 Correct 274 ms 29176 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 15 ms 8320 KB Output is correct
13 Correct 243 ms 29284 KB Output is correct
14 Correct 5 ms 7424 KB Output is correct
15 Correct 6 ms 7336 KB Output is correct
16 Correct 10 ms 7680 KB Output is correct
17 Correct 120 ms 15224 KB Output is correct
18 Correct 5 ms 7424 KB Output is correct
19 Correct 5 ms 7424 KB Output is correct
20 Correct 66 ms 13016 KB Output is correct
21 Correct 252 ms 29176 KB Output is correct
22 Correct 256 ms 29176 KB Output is correct
23 Correct 279 ms 29304 KB Output is correct
24 Correct 248 ms 29412 KB Output is correct
25 Correct 102 ms 15224 KB Output is correct
26 Correct 101 ms 15352 KB Output is correct
27 Correct 278 ms 29340 KB Output is correct
28 Correct 243 ms 29432 KB Output is correct
29 Correct 5 ms 7424 KB Output is correct
30 Correct 5 ms 7424 KB Output is correct
31 Correct 5 ms 7424 KB Output is correct
32 Correct 5 ms 7424 KB Output is correct
33 Correct 5 ms 7424 KB Output is correct
34 Correct 5 ms 7424 KB Output is correct
35 Correct 5 ms 7424 KB Output is correct
36 Correct 15 ms 8320 KB Output is correct
37 Correct 242 ms 29180 KB Output is correct
38 Correct 5 ms 7424 KB Output is correct
39 Correct 5 ms 7424 KB Output is correct
40 Correct 16 ms 8320 KB Output is correct
41 Correct 266 ms 29276 KB Output is correct
42 Correct 6 ms 7424 KB Output is correct
43 Correct 5 ms 7424 KB Output is correct
44 Correct 10 ms 7680 KB Output is correct
45 Correct 120 ms 15336 KB Output is correct
46 Correct 6 ms 7424 KB Output is correct
47 Correct 5 ms 7424 KB Output is correct
48 Correct 5 ms 7424 KB Output is correct
49 Correct 66 ms 12896 KB Output is correct
50 Correct 252 ms 29304 KB Output is correct
51 Correct 249 ms 29304 KB Output is correct
52 Correct 275 ms 29176 KB Output is correct
53 Correct 103 ms 19320 KB Output is correct
54 Correct 104 ms 15352 KB Output is correct
55 Correct 247 ms 29176 KB Output is correct
56 Correct 278 ms 29176 KB Output is correct
57 Correct 105 ms 19320 KB Output is correct
58 Correct 5 ms 7424 KB Output is correct
59 Correct 5 ms 7424 KB Output is correct
60 Correct 5 ms 7424 KB Output is correct
61 Correct 66 ms 12920 KB Output is correct
62 Correct 255 ms 29176 KB Output is correct
63 Correct 254 ms 29200 KB Output is correct
64 Correct 275 ms 29156 KB Output is correct
65 Correct 5 ms 7424 KB Output is correct
66 Correct 68 ms 12920 KB Output is correct
67 Correct 254 ms 29260 KB Output is correct
68 Correct 245 ms 29280 KB Output is correct
69 Correct 273 ms 29176 KB Output is correct
70 Correct 5 ms 7424 KB Output is correct
71 Correct 5 ms 7424 KB Output is correct
72 Correct 5 ms 7424 KB Output is correct
73 Correct 65 ms 12920 KB Output is correct
74 Correct 253 ms 29304 KB Output is correct
75 Correct 249 ms 29176 KB Output is correct
76 Correct 247 ms 29176 KB Output is correct
77 Correct 248 ms 29176 KB Output is correct
78 Correct 5 ms 7424 KB Output is correct
79 Correct 5 ms 7424 KB Output is correct
80 Correct 10 ms 7680 KB Output is correct
81 Correct 120 ms 15224 KB Output is correct
82 Correct 5 ms 7424 KB Output is correct
83 Correct 5 ms 7424 KB Output is correct
84 Correct 5 ms 7424 KB Output is correct
85 Correct 69 ms 12920 KB Output is correct
86 Correct 105 ms 15228 KB Output is correct
87 Correct 102 ms 15228 KB Output is correct
88 Correct 100 ms 15228 KB Output is correct
89 Correct 106 ms 19320 KB Output is correct
90 Correct 5 ms 7424 KB Output is correct
91 Correct 5 ms 7424 KB Output is correct
92 Correct 9 ms 7680 KB Output is correct
93 Correct 116 ms 15352 KB Output is correct
94 Correct 5 ms 7552 KB Output is correct
95 Correct 5 ms 7424 KB Output is correct
96 Correct 5 ms 7424 KB Output is correct
97 Correct 30 ms 9344 KB Output is correct
98 Correct 98 ms 15224 KB Output is correct
99 Correct 104 ms 15480 KB Output is correct
100 Correct 107 ms 15352 KB Output is correct
101 Correct 100 ms 15224 KB Output is correct
102 Correct 108 ms 15224 KB Output is correct
103 Correct 108 ms 15352 KB Output is correct
104 Correct 109 ms 15352 KB Output is correct
105 Correct 108 ms 15224 KB Output is correct