Submission #307113

# Submission time Handle Problem Language Result Execution time Memory
307113 2020-09-27T06:29:16 Z cheetose Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
265 ms 22264 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<db> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };
#include "supertrees.h"
int parent[1000];
int find(int a)
{
	if (parent[a] < 0)return a;
	return parent[a] = find(parent[a]);
}
void merge(int a, int b)
{
	a = find(a), b = find(b);
	if (a != b)
	{
		parent[b] = a;
	}
}
Vi v[1000];
bool chk[1000];
int construct(vector<Vi> p){
	MEM_1(parent);
	int n=p.size();
	vector<Vi> b(n,Vi(n));
	/*int mx=1;
	fup(i,0,n-1,1){
		fup(j,i+1,n-1,1){
			mx=max(mx,p[i][j]);
		}
	}
	if(mx==3){
		fup(i,0,n-1,1){
			fup(j,i+1,n-1,1)if(p[i][j]==2)return 0;
		}
	}*/
	fup(i,0,n-1,1){
		fup(j,i+1,n-1,1){
			if(p[i][j]==3)return 0;
			if(p[i][j]==1){
				chk[i]=chk[j]=1;
				merge(i,j);
			}
		}
	}
	fup(i,0,n-1,1){
		fup(j,i+1,n-1,1){
			if(p[i][j]==2 && find(i)==find(j))return 0;
			if(p[i][j]==1){
				if(i!=find(i))b[i][find(i)]=b[find(i)][i]=1;
				if(j!=find(j))b[j][find(j)]=b[find(j)][j]=1;
			}
		}
	}
	fup(i,0,n-1,1){
		fup(j,i+1,n-1,1){
			if(p[i][j]==2){
				int ii=find(i),jj=find(j);
				if(ii==jj)continue;
				if(chk[ii]){
					v[ii].pb(jj);
					parent[jj]=ii;
				}else{
					v[jj].pb(ii);
					parent[ii]=jj;
				}
			}
		}
	}
	fup(i,0,n-1,1){
		fup(j,i+1,n-1,1){
			if(p[i][j]==0 && find(i)==find(j))return 0;
		}
	}
	fup(i,0,n-1,1){
		if(i!=find(i)){
			int j=find(i);
			while(!v[i].empty()){
				v[j].pb(v[i].back());
				v[i].pop_back();
			}
		}
	}
	fup(i,0,n-1,1){
		int N=v[i].size();
		if(N==1)return 0;
		if(N>1){
			fup(j,0,N-1,1){
				if(j==0)b[i][v[i][j]]=b[v[i][j]][i]=1;
				else b[v[i][j]][v[i][j-1]]=b[v[i][j-1]][v[i][j]]=1;
				if(j==N-1)b[i][v[i][j]]=b[v[i][j]][i]=1;
			}
		}
	}
	build(b);
	return 1;
}/*
int main() {
}*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
supertrees.cpp:75:2: note: in expansion of macro 'fup'
   75 |  fup(i,0,n-1,1){
      |  ^~~
supertrees.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
supertrees.cpp:76:3: note: in expansion of macro 'fup'
   76 |   fup(j,i+1,n-1,1){
      |   ^~~
supertrees.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
supertrees.cpp:84:2: note: in expansion of macro 'fup'
   84 |  fup(i,0,n-1,1){
      |  ^~~
supertrees.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
supertrees.cpp:85:3: note: in expansion of macro 'fup'
   85 |   fup(j,i+1,n-1,1){
      |   ^~~
supertrees.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
supertrees.cpp:93:2: note: in expansion of macro 'fup'
   93 |  fup(i,0,n-1,1){
      |  ^~~
supertrees.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
supertrees.cpp:94:3: note: in expansion of macro 'fup'
   94 |   fup(j,i+1,n-1,1){
      |   ^~~
supertrees.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
supertrees.cpp:108:2: note: in expansion of macro 'fup'
  108 |  fup(i,0,n-1,1){
      |  ^~~
supertrees.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
supertrees.cpp:109:3: note: in expansion of macro 'fup'
  109 |   fup(j,i+1,n-1,1){
      |   ^~~
supertrees.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
supertrees.cpp:113:2: note: in expansion of macro 'fup'
  113 |  fup(i,0,n-1,1){
      |  ^~~
supertrees.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
supertrees.cpp:122:2: note: in expansion of macro 'fup'
  122 |  fup(i,0,n-1,1){
      |  ^~~
supertrees.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
supertrees.cpp:126:4: note: in expansion of macro 'fup'
  126 |    fup(j,0,N-1,1){
      |    ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 260 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 260 ms 22136 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 230 ms 22128 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 7 ms 768 KB Output is correct
17 Correct 125 ms 12152 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 5880 KB Output is correct
21 Correct 239 ms 22264 KB Output is correct
22 Correct 233 ms 22136 KB Output is correct
23 Correct 261 ms 22136 KB Output is correct
24 Correct 230 ms 22136 KB Output is correct
25 Correct 103 ms 12152 KB Output is correct
26 Correct 103 ms 12284 KB Output is correct
27 Correct 265 ms 22264 KB Output is correct
28 Correct 238 ms 22264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 10 ms 1280 KB Output is correct
9 Correct 232 ms 22132 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 11 ms 1280 KB Output is correct
13 Correct 250 ms 22132 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 123 ms 12276 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 61 ms 5880 KB Output is correct
22 Correct 239 ms 22136 KB Output is correct
23 Correct 243 ms 22136 KB Output is correct
24 Correct 254 ms 22132 KB Output is correct
25 Correct 103 ms 12152 KB Output is correct
26 Correct 102 ms 12280 KB Output is correct
27 Correct 243 ms 22136 KB Output is correct
28 Correct 259 ms 22136 KB Output is correct
29 Correct 102 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 63 ms 5860 KB Output is correct
5 Correct 244 ms 22136 KB Output is correct
6 Correct 239 ms 22136 KB Output is correct
7 Correct 263 ms 22136 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 59 ms 5880 KB Output is correct
10 Correct 247 ms 22220 KB Output is correct
11 Correct 234 ms 22136 KB Output is correct
12 Correct 260 ms 22264 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 60 ms 5880 KB Output is correct
17 Correct 240 ms 22136 KB Output is correct
18 Correct 241 ms 22136 KB Output is correct
19 Correct 237 ms 22136 KB Output is correct
20 Correct 228 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 260 ms 22136 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 230 ms 22128 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 7 ms 768 KB Output is correct
17 Correct 125 ms 12152 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 5880 KB Output is correct
21 Correct 239 ms 22264 KB Output is correct
22 Correct 233 ms 22136 KB Output is correct
23 Correct 261 ms 22136 KB Output is correct
24 Correct 230 ms 22136 KB Output is correct
25 Correct 103 ms 12152 KB Output is correct
26 Correct 103 ms 12284 KB Output is correct
27 Correct 265 ms 22264 KB Output is correct
28 Correct 238 ms 22264 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 288 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 232 ms 22132 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 11 ms 1280 KB Output is correct
41 Correct 250 ms 22132 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 123 ms 12276 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 61 ms 5880 KB Output is correct
50 Correct 239 ms 22136 KB Output is correct
51 Correct 243 ms 22136 KB Output is correct
52 Correct 254 ms 22132 KB Output is correct
53 Correct 103 ms 12152 KB Output is correct
54 Correct 102 ms 12280 KB Output is correct
55 Correct 243 ms 22136 KB Output is correct
56 Correct 259 ms 22136 KB Output is correct
57 Correct 102 ms 12152 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 5 ms 768 KB Output is correct
61 Correct 118 ms 12152 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 0 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 59 ms 5880 KB Output is correct
66 Correct 101 ms 12152 KB Output is correct
67 Correct 102 ms 12156 KB Output is correct
68 Correct 98 ms 12152 KB Output is correct
69 Correct 96 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 260 ms 22136 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 230 ms 22128 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 7 ms 768 KB Output is correct
17 Correct 125 ms 12152 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 5880 KB Output is correct
21 Correct 239 ms 22264 KB Output is correct
22 Correct 233 ms 22136 KB Output is correct
23 Correct 261 ms 22136 KB Output is correct
24 Correct 230 ms 22136 KB Output is correct
25 Correct 103 ms 12152 KB Output is correct
26 Correct 103 ms 12284 KB Output is correct
27 Correct 265 ms 22264 KB Output is correct
28 Correct 238 ms 22264 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 288 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 232 ms 22132 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 11 ms 1280 KB Output is correct
41 Correct 250 ms 22132 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 123 ms 12276 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 61 ms 5880 KB Output is correct
50 Correct 239 ms 22136 KB Output is correct
51 Correct 243 ms 22136 KB Output is correct
52 Correct 254 ms 22132 KB Output is correct
53 Correct 103 ms 12152 KB Output is correct
54 Correct 102 ms 12280 KB Output is correct
55 Correct 243 ms 22136 KB Output is correct
56 Correct 259 ms 22136 KB Output is correct
57 Correct 102 ms 12152 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 0 ms 384 KB Output is correct
61 Correct 63 ms 5860 KB Output is correct
62 Correct 244 ms 22136 KB Output is correct
63 Correct 239 ms 22136 KB Output is correct
64 Correct 263 ms 22136 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 59 ms 5880 KB Output is correct
67 Correct 247 ms 22220 KB Output is correct
68 Correct 234 ms 22136 KB Output is correct
69 Correct 260 ms 22264 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 60 ms 5880 KB Output is correct
74 Correct 240 ms 22136 KB Output is correct
75 Correct 241 ms 22136 KB Output is correct
76 Correct 237 ms 22136 KB Output is correct
77 Correct 228 ms 22136 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 5 ms 768 KB Output is correct
81 Correct 118 ms 12152 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 0 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 59 ms 5880 KB Output is correct
86 Correct 101 ms 12152 KB Output is correct
87 Correct 102 ms 12156 KB Output is correct
88 Correct 98 ms 12152 KB Output is correct
89 Correct 96 ms 12152 KB Output is correct
90 Correct 0 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 6 ms 768 KB Output is correct
93 Correct 116 ms 12152 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 25 ms 3328 KB Output is correct
98 Correct 105 ms 12152 KB Output is correct
99 Correct 97 ms 12152 KB Output is correct
100 Correct 95 ms 12156 KB Output is correct
101 Correct 95 ms 12152 KB Output is correct
102 Correct 112 ms 12144 KB Output is correct
103 Correct 113 ms 12152 KB Output is correct
104 Correct 112 ms 12152 KB Output is correct
105 Correct 109 ms 12152 KB Output is correct