답안 #303760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
303760 2020-09-20T15:46:21 Z Hemimor 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
287 ms 30168 KB
#include "supertrees.h"
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,N;
vvi p,c,g,G;
vi b,vis,ind;

void dfs(int v,int t){
	vis[v]=1;
	ind[v]=t;
	b.push_back(v);
	for(int i=0;i<n;i++) if(i!=v&&p[v][i]==1&&!vis[i]) dfs(i,t);
}

void DFS(int v){
	vis[v]=1;
	b.push_back(v);
	for(int i=0;i<N;i++) if(i!=v&&G[v][i]==1&&!vis[i]) DFS(i);
}

int construct(vvi p_){
	p=p_;
	n=p.size();
	vis=ind=vi(n);
	g=vvi(n,vi(n));
	int id=0;
	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++) if(!vis[i]){
		b.clear();
		dfs(i,id);
		int m=b.size();
		for(auto v:b) for(auto u:b) if(p[u][v]!=1) return 0;
		for(int j=1;j<m;j++){
			int u=b[j-1],v=b[j];
			g[u][v]=g[v][u]=1;
		}
		id++;
		c.push_back(b);
	}
	N=c.size();
	G=vvi(N,vi(N));
	for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) if(p[i][j]==2){
		int u=ind[i],v=ind[j];
		G[u][v]=G[v][u]=1;
	}
	vis=vi(N);
	for(int i=0;i<N;i++) if(!vis[i]){
		b.clear();
		DFS(i);
		int m=b.size();
		for(auto I:b) for(auto J:b) if(I<J){
			for(auto u:c[I]) for(auto v:c[J]) if(p[u][v]!=2) return 0;
		}
		if(m==1) continue;
		if(m==2) return 0;
		for(int j=0;j<m;j++){
			int u=c[b[j]][0],v=c[b[(j+1)%m]][0];
			g[u][v]=g[v][u]=1;
		}
	}
	build(g);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 255 ms 26104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 255 ms 26104 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1536 KB Output is correct
13 Correct 250 ms 30116 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 124 ms 16216 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 61 ms 6776 KB Output is correct
21 Correct 241 ms 26104 KB Output is correct
22 Correct 244 ms 26704 KB Output is correct
23 Correct 287 ms 26104 KB Output is correct
24 Correct 251 ms 29688 KB Output is correct
25 Correct 109 ms 16120 KB Output is correct
26 Correct 100 ms 16120 KB Output is correct
27 Correct 266 ms 26104 KB Output is correct
28 Correct 245 ms 29688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 14 ms 1536 KB Output is correct
9 Correct 279 ms 30044 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 15 ms 1536 KB Output is correct
13 Correct 273 ms 30036 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 129 ms 20216 KB Output is correct
18 Correct 1 ms 360 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 62 ms 7892 KB Output is correct
22 Correct 276 ms 30036 KB Output is correct
23 Correct 245 ms 30076 KB Output is correct
24 Correct 274 ms 30072 KB Output is correct
25 Correct 109 ms 20216 KB Output is correct
26 Correct 113 ms 20188 KB Output is correct
27 Correct 265 ms 30168 KB Output is correct
28 Correct 259 ms 30036 KB Output is correct
29 Correct 110 ms 20164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 64 ms 6780 KB Output is correct
5 Correct 270 ms 26104 KB Output is correct
6 Correct 252 ms 26840 KB Output is correct
7 Correct 260 ms 26088 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 65 ms 7800 KB Output is correct
10 Correct 262 ms 30040 KB Output is correct
11 Correct 260 ms 30088 KB Output is correct
12 Correct 271 ms 30036 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 63 ms 7520 KB Output is correct
17 Correct 253 ms 30072 KB Output is correct
18 Correct 249 ms 27384 KB Output is correct
19 Correct 265 ms 27640 KB Output is correct
20 Correct 243 ms 29944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 255 ms 26104 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1536 KB Output is correct
13 Correct 250 ms 30116 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 124 ms 16216 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 61 ms 6776 KB Output is correct
21 Correct 241 ms 26104 KB Output is correct
22 Correct 244 ms 26704 KB Output is correct
23 Correct 287 ms 26104 KB Output is correct
24 Correct 251 ms 29688 KB Output is correct
25 Correct 109 ms 16120 KB Output is correct
26 Correct 100 ms 16120 KB Output is correct
27 Correct 266 ms 26104 KB Output is correct
28 Correct 245 ms 29688 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 14 ms 1536 KB Output is correct
37 Correct 279 ms 30044 KB Output is correct
38 Correct 0 ms 256 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 15 ms 1536 KB Output is correct
41 Correct 273 ms 30036 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 6 ms 1152 KB Output is correct
45 Correct 129 ms 20216 KB Output is correct
46 Correct 1 ms 360 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 62 ms 7892 KB Output is correct
50 Correct 276 ms 30036 KB Output is correct
51 Correct 245 ms 30076 KB Output is correct
52 Correct 274 ms 30072 KB Output is correct
53 Correct 109 ms 20216 KB Output is correct
54 Correct 113 ms 20188 KB Output is correct
55 Correct 265 ms 30168 KB Output is correct
56 Correct 259 ms 30036 KB Output is correct
57 Correct 110 ms 20164 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 5 ms 1024 KB Output is correct
61 Correct 126 ms 16216 KB Output is correct
62 Correct 0 ms 256 KB Output is correct
63 Correct 0 ms 256 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 61 ms 7544 KB Output is correct
66 Correct 110 ms 20088 KB Output is correct
67 Correct 104 ms 16120 KB Output is correct
68 Correct 105 ms 17400 KB Output is correct
69 Correct 104 ms 19924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 255 ms 26104 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1536 KB Output is correct
13 Correct 250 ms 30116 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 124 ms 16216 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 61 ms 6776 KB Output is correct
21 Correct 241 ms 26104 KB Output is correct
22 Correct 244 ms 26704 KB Output is correct
23 Correct 287 ms 26104 KB Output is correct
24 Correct 251 ms 29688 KB Output is correct
25 Correct 109 ms 16120 KB Output is correct
26 Correct 100 ms 16120 KB Output is correct
27 Correct 266 ms 26104 KB Output is correct
28 Correct 245 ms 29688 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 14 ms 1536 KB Output is correct
37 Correct 279 ms 30044 KB Output is correct
38 Correct 0 ms 256 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 15 ms 1536 KB Output is correct
41 Correct 273 ms 30036 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 6 ms 1152 KB Output is correct
45 Correct 129 ms 20216 KB Output is correct
46 Correct 1 ms 360 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 62 ms 7892 KB Output is correct
50 Correct 276 ms 30036 KB Output is correct
51 Correct 245 ms 30076 KB Output is correct
52 Correct 274 ms 30072 KB Output is correct
53 Correct 109 ms 20216 KB Output is correct
54 Correct 113 ms 20188 KB Output is correct
55 Correct 265 ms 30168 KB Output is correct
56 Correct 259 ms 30036 KB Output is correct
57 Correct 110 ms 20164 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 0 ms 256 KB Output is correct
61 Correct 64 ms 6780 KB Output is correct
62 Correct 270 ms 26104 KB Output is correct
63 Correct 252 ms 26840 KB Output is correct
64 Correct 260 ms 26088 KB Output is correct
65 Correct 1 ms 256 KB Output is correct
66 Correct 65 ms 7800 KB Output is correct
67 Correct 262 ms 30040 KB Output is correct
68 Correct 260 ms 30088 KB Output is correct
69 Correct 271 ms 30036 KB Output is correct
70 Correct 1 ms 256 KB Output is correct
71 Correct 0 ms 256 KB Output is correct
72 Correct 1 ms 256 KB Output is correct
73 Correct 63 ms 7520 KB Output is correct
74 Correct 253 ms 30072 KB Output is correct
75 Correct 249 ms 27384 KB Output is correct
76 Correct 265 ms 27640 KB Output is correct
77 Correct 243 ms 29944 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 0 ms 256 KB Output is correct
80 Correct 5 ms 1024 KB Output is correct
81 Correct 126 ms 16216 KB Output is correct
82 Correct 0 ms 256 KB Output is correct
83 Correct 0 ms 256 KB Output is correct
84 Correct 1 ms 256 KB Output is correct
85 Correct 61 ms 7544 KB Output is correct
86 Correct 110 ms 20088 KB Output is correct
87 Correct 104 ms 16120 KB Output is correct
88 Correct 105 ms 17400 KB Output is correct
89 Correct 104 ms 19924 KB Output is correct
90 Correct 1 ms 256 KB Output is correct
91 Correct 0 ms 256 KB Output is correct
92 Correct 5 ms 896 KB Output is correct
93 Correct 111 ms 16084 KB Output is correct
94 Correct 1 ms 256 KB Output is correct
95 Correct 0 ms 256 KB Output is correct
96 Correct 1 ms 256 KB Output is correct
97 Correct 26 ms 4344 KB Output is correct
98 Correct 101 ms 16120 KB Output is correct
99 Correct 109 ms 16120 KB Output is correct
100 Correct 105 ms 16120 KB Output is correct
101 Correct 103 ms 16084 KB Output is correct
102 Correct 113 ms 16088 KB Output is correct
103 Correct 108 ms 16120 KB Output is correct
104 Correct 108 ms 16120 KB Output is correct
105 Correct 116 ms 16120 KB Output is correct