Submission #420152

# Submission time Handle Problem Language Result Execution time Memory
420152 2021-06-08T06:47:22 Z Belgutei Connecting Supertrees (IOI20_supertrees) C++17
40 / 100
506 ms 24016 KB
#include "supertrees.h"
#include<bits/stdc++.h>

using namespace std;

#define mk make_pair
#define ff first
#define ss second
#define pb push_back

map<int,int> mp;
vector<int> tree[1005];


int construct(std::vector<std::vector<int> > p) {
	int n=p.size();
	std::vector<std::vector<int> > answer;
	answer.resize(n);
	bool c1=0,cc=0;
	for(int i=0; i<p.size(); i++){
		for(int j=0; j<p[i].size(); j++){
			answer[i].resize(n);
			if(p[i][j]>=2) c1=1;
			if(i==j) continue;
			if(p[i][j]==1 || p[i][j]==3) cc=1;
		}
	}
	if(c1==0){
		// subtask 1,2
		int cnt=0;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(i==j) continue;
				if(p[i][j]==1){
					if(mp[i]==0 && mp[j]==0){
						cnt++;
						mp[i]=cnt;
						mp[j]=cnt;
						tree[cnt].pb(i);
						tree[cnt].pb(j);
						continue;
					}
					if(mp[i]==0){
						mp[i]=mp[j];
						tree[mp[i]].pb(i);
						continue;
					}
					if(mp[j]==0){
						mp[j]=mp[i];
						tree[mp[j]].pb(j);
						continue;
					}
					if(mp[i]!=mp[j]) return 0;
				}
			}
		}
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(i==j) continue;
				if(mp[i]!=mp[j] && p[i][j]==1) return 0;
				if(mp[i]==mp[j] && p[i][j]==0 && mp[i]!=0) return 0;
			}
		}
		for(int i=1; i<=cnt; i++){
			for(int j=1; j<tree[i].size(); j++){
				answer[tree[i][j]][tree[i][j-1]]=1;
				answer[tree[i][j-1]][tree[i][j]]=1;
			}
		}
		build(answer);
		return 1;
	}
	if(cc==0){
		// subtask 2
		int cnt=0;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(i==j) continue;
				if(p[i][j]==2){
					if(mp[i]==0 && mp[j]==0){
						cnt++;
						mp[i]=cnt;
						mp[j]=cnt;
						tree[cnt].pb(i);
						tree[cnt].pb(j);
						continue;
					}
					if(mp[i]==0){
						mp[i]=mp[j];
						tree[mp[i]].pb(i);
						continue;
					}
					if(mp[j]==0){
						mp[j]=mp[i];
						tree[mp[j]].pb(j);
						continue;
					}
					if(mp[i]!=mp[j]) return 0;
				}
			}
		}
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(i==j) continue;
				if(mp[i]!=mp[j] && p[i][j]==2) return 0;
				if(mp[i]==mp[j] && p[i][j]==0 && mp[i]!=0) return 0;
			}
		}
		for(int i=1; i<=cnt; i++){
			if(tree[i].size()==2) return 0;
			for(int j=1; j<tree[i].size(); j++){
				answer[tree[i][j]][tree[i][j-1]]=1;
				answer[tree[i][j-1]][tree[i][j]]=1;
			}
			answer[tree[i][0]][tree[i][tree[i].size()-1]]=1;
			answer[tree[i][tree[i].size()-1]][tree[i][0]]=1;
			
		}
		build(answer);
		return 1;
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:20:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i=0; i<p.size(); i++){
      |               ~^~~~~~~~~
supertrees.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for(int j=0; j<p[i].size(); j++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |    for(int j=1; j<tree[i].size(); j++){
      |                 ~^~~~~~~~~~~~~~~
supertrees.cpp:111:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |    for(int j=1; j<tree[i].size(); j++){
      |                 ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 19 ms 1180 KB Output is correct
7 Correct 504 ms 22124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 19 ms 1180 KB Output is correct
7 Correct 504 ms 22124 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 18 ms 1176 KB Output is correct
13 Correct 373 ms 22036 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 8 ms 696 KB Output is correct
17 Correct 200 ms 12200 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 93 ms 5740 KB Output is correct
21 Correct 364 ms 22056 KB Output is correct
22 Correct 351 ms 22028 KB Output is correct
23 Correct 480 ms 22096 KB Output is correct
24 Correct 363 ms 22048 KB Output is correct
25 Correct 119 ms 12192 KB Output is correct
26 Correct 124 ms 12176 KB Output is correct
27 Correct 499 ms 22032 KB Output is correct
28 Correct 361 ms 22096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 17 ms 1192 KB Output is correct
9 Correct 345 ms 22044 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 19 ms 1148 KB Output is correct
13 Correct 506 ms 22036 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 8 ms 716 KB Output is correct
17 Correct 194 ms 12192 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 87 ms 5780 KB Output is correct
22 Correct 382 ms 22088 KB Output is correct
23 Correct 355 ms 22060 KB Output is correct
24 Correct 453 ms 22120 KB Output is correct
25 Correct 227 ms 12100 KB Output is correct
26 Correct 99 ms 14096 KB Output is correct
27 Correct 361 ms 24016 KB Output is correct
28 Correct 453 ms 23968 KB Output is correct
29 Correct 300 ms 14152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 133 ms 5736 KB Output is correct
5 Correct 427 ms 22120 KB Output is correct
6 Correct 372 ms 22100 KB Output is correct
7 Correct 506 ms 22052 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 87 ms 5740 KB Output is correct
10 Correct 369 ms 22032 KB Output is correct
11 Correct 354 ms 22052 KB Output is correct
12 Correct 448 ms 22036 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Incorrect 0 ms 204 KB Too few ways to get from 0 to 1, should be 2 found 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 19 ms 1180 KB Output is correct
7 Correct 504 ms 22124 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 18 ms 1176 KB Output is correct
13 Correct 373 ms 22036 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 8 ms 696 KB Output is correct
17 Correct 200 ms 12200 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 93 ms 5740 KB Output is correct
21 Correct 364 ms 22056 KB Output is correct
22 Correct 351 ms 22028 KB Output is correct
23 Correct 480 ms 22096 KB Output is correct
24 Correct 363 ms 22048 KB Output is correct
25 Correct 119 ms 12192 KB Output is correct
26 Correct 124 ms 12176 KB Output is correct
27 Correct 499 ms 22032 KB Output is correct
28 Correct 361 ms 22096 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 17 ms 1192 KB Output is correct
37 Correct 345 ms 22044 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 19 ms 1148 KB Output is correct
41 Correct 506 ms 22036 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 8 ms 716 KB Output is correct
45 Correct 194 ms 12192 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 87 ms 5780 KB Output is correct
50 Correct 382 ms 22088 KB Output is correct
51 Correct 355 ms 22060 KB Output is correct
52 Correct 453 ms 22120 KB Output is correct
53 Correct 227 ms 12100 KB Output is correct
54 Correct 99 ms 14096 KB Output is correct
55 Correct 361 ms 24016 KB Output is correct
56 Correct 453 ms 23968 KB Output is correct
57 Correct 300 ms 14152 KB Output is correct
58 Incorrect 1 ms 204 KB Answer gives possible 1 while actual possible 0
59 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 19 ms 1180 KB Output is correct
7 Correct 504 ms 22124 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 18 ms 1176 KB Output is correct
13 Correct 373 ms 22036 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 8 ms 696 KB Output is correct
17 Correct 200 ms 12200 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 93 ms 5740 KB Output is correct
21 Correct 364 ms 22056 KB Output is correct
22 Correct 351 ms 22028 KB Output is correct
23 Correct 480 ms 22096 KB Output is correct
24 Correct 363 ms 22048 KB Output is correct
25 Correct 119 ms 12192 KB Output is correct
26 Correct 124 ms 12176 KB Output is correct
27 Correct 499 ms 22032 KB Output is correct
28 Correct 361 ms 22096 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 17 ms 1192 KB Output is correct
37 Correct 345 ms 22044 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 19 ms 1148 KB Output is correct
41 Correct 506 ms 22036 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 8 ms 716 KB Output is correct
45 Correct 194 ms 12192 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 87 ms 5780 KB Output is correct
50 Correct 382 ms 22088 KB Output is correct
51 Correct 355 ms 22060 KB Output is correct
52 Correct 453 ms 22120 KB Output is correct
53 Correct 227 ms 12100 KB Output is correct
54 Correct 99 ms 14096 KB Output is correct
55 Correct 361 ms 24016 KB Output is correct
56 Correct 453 ms 23968 KB Output is correct
57 Correct 300 ms 14152 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 133 ms 5736 KB Output is correct
62 Correct 427 ms 22120 KB Output is correct
63 Correct 372 ms 22100 KB Output is correct
64 Correct 506 ms 22052 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 87 ms 5740 KB Output is correct
67 Correct 369 ms 22032 KB Output is correct
68 Correct 354 ms 22052 KB Output is correct
69 Correct 448 ms 22036 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Incorrect 0 ms 204 KB Too few ways to get from 0 to 1, should be 2 found 0
72 Halted 0 ms 0 KB -