답안 #1051443

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051443 2024-08-10T07:00:48 Z LittleOrange 슈퍼트리 잇기 (IOI20_supertrees) C++17
96 / 100
155 ms 22172 KB
#include "supertrees.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = int;
struct dsu{
	ll n;
	vector<ll> p;
	dsu(ll N):n(N),p(N,-1){}
	ll g(ll i){
		return p[i]<0?i:p[i]=g(p[i]);
	}
	bool e(ll a, ll b){
		return g(a)==g(b);
	}
	bool m(ll a, ll b){
		a = g(a);
		b = g(b);
		if(a==b) return false;
		if (p[a]>p[b]) swap(a,b);
		p[a] += p[b];
		p[b] = a;
		return true;
	}
};

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	vector<vector<ll>> ans(n,vector<ll>(n,0));
	dsu d(n);
	for(ll i = 0;i<n;i++) for(ll j = 0;j<n;j++){
		//if (p[i][j]==3) return 0;
		if (p[i][j]) d.m(i,j);
	}
	for(ll i = 0;i<n;i++) for(ll j = 0;j<n;j++){
		if (!p[i][j]&&d.e(i,j)) return 0;
	}
	vector<ll> g;
	for(ll i = 0;i<n;i++) if(d.g(i)==i) g.push_back(i);
	ll gc = g.size();
	vector<vector<ll>> gs(gc);
	for(ll i = 0;i<n;i++) gs[lower_bound(g.begin(),g.end(),d.g(i))-g.begin()].push_back(i);
	for(auto &o : gs) if(o.size()>1){
		ll ty = 3;
		ll is_1 = 1, is_2 = 1;
		for(ll i : o) for(ll j : o) if(i!=j){
			if (p[i][j]!=1) is_1=0;
			if (p[i][j]!=2) is_2=0;
		}
		if(is_1) ty=1;
		if(is_2) ty=2;
		//cerr << "type=" << ty << endl;
		if (ty!=3){
			for(ll i = 1;i<o.size();i++) ans[o[i-1]][o[i]] = ans[o[i]][o[i-1]] = 1;
			if (ty == 2){
				if (o.size()==2) return 0;
				ans[o.front()][o.back()] = ans[o.back()][o.front()] = 1;
			}
		}else{
			ll m = o.size();
			dsu d(m);
			for(ll i = 0;i<m;i++)for(ll j = 0;j<m;j++) if(i!=j){
				if (p[o[i]][o[j]]==1) {
					//cerr << "gp " << i << " " << j << endl;
					d.m(i,j);
				}
			}
			for(ll i = 0;i<m;i++)for(ll j = 0;j<m;j++) if(i!=j){
				if (d.e(i,j)&&p[o[i]][o[j]]!=1) return 0;
			}
			vector<ll> c;
			for(ll i = 0;i<m;i++) if(d.g(i)==i) c.push_back(i);
			ll cc = c.size();
			//cerr << "cc=" << cc << endl;
			if (cc<3) return 0;
			vector<vector<ll>> cs(cc);
			for(ll i = 0;i<m;i++) cs[lower_bound(c.begin(),c.end(),d.g(i))-c.begin()].push_back(o[i]);
			/*for(ll i = 0;i<cc;i++){
				cerr << "cg " << i << ":";
				for(ll j : cs[i]) cerr << " " << j;
				cerr << "\n";
			}*/
			for(auto &cl : cs){
				for(ll i = 1;i<cl.size();i++) ans[cl[i-1]][cl[i]] = ans[cl[i]][cl[i-1]] = 1;
			}
			for(ll i = 1;i<cc;i++) ans[cs[i-1][0]][cs[i][0]] = ans[cs[i][0]][cs[i-1][0]] = 1;
			ans[cs.front()[0]][cs.back()[0]] = ans[cs.back()[0]][cs.front()[0]] = 1;
		}
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:54:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |    for(ll i = 1;i<o.size();i++) ans[o[i-1]][o[i]] = ans[o[i]][o[i-1]] = 1;
      |                 ~^~~~~~~~~
supertrees.cpp:84:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for(ll i = 1;i<cl.size();i++) ans[cl[i-1]][cl[i]] = ans[cl[i]][cl[i-1]] = 1;
      |                  ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1116 KB Output is correct
7 Correct 94 ms 22060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1116 KB Output is correct
7 Correct 94 ms 22060 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 94 ms 22012 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 50 ms 12044 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 5860 KB Output is correct
21 Correct 97 ms 22040 KB Output is correct
22 Correct 95 ms 22172 KB Output is correct
23 Correct 103 ms 22024 KB Output is correct
24 Correct 93 ms 22112 KB Output is correct
25 Correct 43 ms 12044 KB Output is correct
26 Correct 41 ms 12052 KB Output is correct
27 Correct 103 ms 22100 KB Output is correct
28 Correct 93 ms 22096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 4 ms 1116 KB Output is correct
9 Correct 93 ms 22040 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 96 ms 22004 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 53 ms 12272 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 28 ms 5724 KB Output is correct
22 Correct 95 ms 22096 KB Output is correct
23 Correct 93 ms 22100 KB Output is correct
24 Correct 110 ms 22036 KB Output is correct
25 Correct 43 ms 12112 KB Output is correct
26 Correct 42 ms 12120 KB Output is correct
27 Correct 95 ms 22096 KB Output is correct
28 Correct 99 ms 22040 KB Output is correct
29 Correct 48 ms 12112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 24 ms 5720 KB Output is correct
5 Correct 101 ms 22096 KB Output is correct
6 Correct 105 ms 22096 KB Output is correct
7 Correct 113 ms 22024 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 24 ms 5716 KB Output is correct
10 Correct 96 ms 22100 KB Output is correct
11 Correct 102 ms 22040 KB Output is correct
12 Correct 155 ms 22100 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 25 ms 5692 KB Output is correct
17 Correct 96 ms 22100 KB Output is correct
18 Correct 136 ms 22096 KB Output is correct
19 Correct 97 ms 22024 KB Output is correct
20 Correct 95 ms 22024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1116 KB Output is correct
7 Correct 94 ms 22060 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 94 ms 22012 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 50 ms 12044 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 5860 KB Output is correct
21 Correct 97 ms 22040 KB Output is correct
22 Correct 95 ms 22172 KB Output is correct
23 Correct 103 ms 22024 KB Output is correct
24 Correct 93 ms 22112 KB Output is correct
25 Correct 43 ms 12044 KB Output is correct
26 Correct 41 ms 12052 KB Output is correct
27 Correct 103 ms 22100 KB Output is correct
28 Correct 93 ms 22096 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 4 ms 1116 KB Output is correct
37 Correct 93 ms 22040 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1108 KB Output is correct
41 Correct 96 ms 22004 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 53 ms 12272 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 28 ms 5724 KB Output is correct
50 Correct 95 ms 22096 KB Output is correct
51 Correct 93 ms 22100 KB Output is correct
52 Correct 110 ms 22036 KB Output is correct
53 Correct 43 ms 12112 KB Output is correct
54 Correct 42 ms 12120 KB Output is correct
55 Correct 95 ms 22096 KB Output is correct
56 Correct 99 ms 22040 KB Output is correct
57 Correct 48 ms 12112 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 2 ms 860 KB Output is correct
61 Correct 48 ms 12056 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 23 ms 5720 KB Output is correct
66 Correct 42 ms 12052 KB Output is correct
67 Correct 47 ms 12112 KB Output is correct
68 Correct 41 ms 12040 KB Output is correct
69 Correct 42 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1116 KB Output is correct
7 Correct 94 ms 22060 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 94 ms 22012 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 50 ms 12044 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 5860 KB Output is correct
21 Correct 97 ms 22040 KB Output is correct
22 Correct 95 ms 22172 KB Output is correct
23 Correct 103 ms 22024 KB Output is correct
24 Correct 93 ms 22112 KB Output is correct
25 Correct 43 ms 12044 KB Output is correct
26 Correct 41 ms 12052 KB Output is correct
27 Correct 103 ms 22100 KB Output is correct
28 Correct 93 ms 22096 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 4 ms 1116 KB Output is correct
37 Correct 93 ms 22040 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1108 KB Output is correct
41 Correct 96 ms 22004 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 53 ms 12272 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 28 ms 5724 KB Output is correct
50 Correct 95 ms 22096 KB Output is correct
51 Correct 93 ms 22100 KB Output is correct
52 Correct 110 ms 22036 KB Output is correct
53 Correct 43 ms 12112 KB Output is correct
54 Correct 42 ms 12120 KB Output is correct
55 Correct 95 ms 22096 KB Output is correct
56 Correct 99 ms 22040 KB Output is correct
57 Correct 48 ms 12112 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 24 ms 5720 KB Output is correct
62 Correct 101 ms 22096 KB Output is correct
63 Correct 105 ms 22096 KB Output is correct
64 Correct 113 ms 22024 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 24 ms 5716 KB Output is correct
67 Correct 96 ms 22100 KB Output is correct
68 Correct 102 ms 22040 KB Output is correct
69 Correct 155 ms 22100 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 25 ms 5692 KB Output is correct
74 Correct 96 ms 22100 KB Output is correct
75 Correct 136 ms 22096 KB Output is correct
76 Correct 97 ms 22024 KB Output is correct
77 Correct 95 ms 22024 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 2 ms 860 KB Output is correct
81 Correct 48 ms 12056 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 23 ms 5720 KB Output is correct
86 Correct 42 ms 12052 KB Output is correct
87 Correct 47 ms 12112 KB Output is correct
88 Correct 41 ms 12040 KB Output is correct
89 Correct 42 ms 12116 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 344 KB Output is correct
92 Correct 2 ms 860 KB Output is correct
93 Correct 49 ms 12056 KB Output is correct
94 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -