# | Submission time^{} |
Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|

314053 | 2020-10-18T01:53:14 Z | linear00000 | Connecting Supertrees (IOI20_supertrees) | C++14 | 267 ms | 22268 KB |

#include "supertrees.h" #include <bits/stdc++.h> using namespace std; vector<vector<int> > d; vector<int> C[1004]; int par[1004], num = 0; int findpar(int N) { if (N == par[N]) return N; else return par[N] = findpar(par[N]); } void merge(int a, int b) { int aa = findpar(a), bb = findpar(b); par[aa] = bb; } int construct(vector<vector<int> > v) { int n = v.size(); for (int i=0; i<n; i++) par[i] = i; d.resize(n); for (int i=0; i<n; i++) d[i].resize(n); // checking int type = 0; for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { if (v[i][j] == 2) { type = 2; break; } if (v[i][j] == 1) type = 1; } if (type == 2) break; } if (type == 2) { for (int i=0; i<n; i++) { for (int j=i + 1; j < n; j++) { if (v[i][j] == 2 && i != j) merge(i, j); } } for (int i=0; i<n; i++) { for (int j=i + 1; j < n; j++) { if (v[i][j] == 0) { if (findpar(i) == findpar(j)) return 0; } } } for (int i=0; i<n; i++) par[i] = findpar(i); for (int i=0; i<n; i++) C[par[i]].push_back(i); for (int i=0; i<n; i++) { int cnt = 0; if (C[i].size() == 2) return 0; else if (C[i].size() >= 3) { for (int j=0; j<C[i].size() - 1; j++) { d[C[i][j]][C[i][j + 1]] = 1, d[C[i][j + 1]][C[i][j]] = 1; } d[C[i][C[i].size() - 1]][C[i][0]] = 1, d[C[i][0]][C[i][C[i].size() - 1]] = 1; } } } else { for (int i=0; i<n; i++) { for (int j=i + 1; j < n; j++) { if (v[i][j] == 1 && i != j) merge(i, j); } } for (int i=0; i<n; i++) { for (int j=i + 1; j < n; j++) { if (v[i][j] == 0) { if (findpar(i) == findpar(j)) return 0; } } } for (int i=0; i<n; i++) par[i] = findpar(i); for (int i=0; i<n; i++) C[par[i]].push_back(i); for (int i=0; i<n; i++) { for (int j=0; j<C[i].size(); j++) { if (C[i][j] != i) d[i][C[i][j]] = 1, d[C[i][j]][i] = 1; } } } build(d); return 1; }

### Compilation message

# | 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 | 512 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 | 247 ms | 22116 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 | 512 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 | 247 ms | 22116 KB | Output is correct |

8 | Correct | 0 ms | 384 KB | Output is correct |

9 | Correct | 0 ms | 384 KB | Output is correct |

10 | Correct | 0 ms | 384 KB | Output is correct |

11 | Correct | 0 ms | 384 KB | Output is correct |

12 | Correct | 10 ms | 1280 KB | Output is correct |

13 | Correct | 237 ms | 22136 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 | 114 ms | 12152 KB | Output is correct |

18 | Correct | 1 ms | 384 KB | Output is correct |

19 | Correct | 0 ms | 384 KB | Output is correct |

20 | Correct | 61 ms | 5876 KB | Output is correct |

21 | Correct | 248 ms | 22136 KB | Output is correct |

22 | Correct | 255 ms | 22124 KB | Output is correct |

23 | Correct | 258 ms | 22132 KB | Output is correct |

24 | Correct | 236 ms | 22264 KB | Output is correct |

25 | Correct | 100 ms | 12152 KB | Output is correct |

26 | Correct | 100 ms | 12152 KB | Output is correct |

27 | Correct | 254 ms | 22136 KB | Output is correct |

28 | Correct | 243 ms | 22264 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 | 0 ms | 384 KB | Output is correct |

4 | Correct | 1 ms | 360 KB | Output is correct |

5 | Correct | 0 ms | 384 KB | Output is correct |

6 | Correct | 0 ms | 384 KB | Output is correct |

7 | Correct | 1 ms | 384 KB | Output is correct |

8 | Correct | 10 ms | 1280 KB | Output is correct |

9 | Correct | 241 ms | 22128 KB | Output is correct |

10 | Correct | 0 ms | 384 KB | Output is correct |

11 | Correct | 0 ms | 384 KB | Output is correct |

12 | Correct | 10 ms | 1280 KB | Output is correct |

13 | Correct | 250 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 | 5 ms | 768 KB | Output is correct |

17 | Correct | 115 ms | 12152 KB | Output is correct |

18 | Correct | 1 ms | 384 KB | Output is correct |

19 | Correct | 0 ms | 384 KB | Output is correct |

20 | Correct | 1 ms | 384 KB | Output is correct |

21 | Correct | 64 ms | 5884 KB | Output is correct |

22 | Correct | 245 ms | 22156 KB | Output is correct |

23 | Correct | 235 ms | 22136 KB | Output is correct |

24 | Correct | 250 ms | 22132 KB | Output is correct |

25 | Correct | 97 ms | 12152 KB | Output is correct |

26 | Correct | 110 ms | 12156 KB | Output is correct |

27 | Correct | 234 ms | 22136 KB | Output is correct |

28 | Correct | 254 ms | 22100 KB | Output is correct |

29 | Correct | 96 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 | 1 ms | 384 KB | Output is correct |

4 | Correct | 63 ms | 5992 KB | Output is correct |

5 | Correct | 239 ms | 22136 KB | Output is correct |

6 | Correct | 241 ms | 22268 KB | Output is correct |

7 | Correct | 260 ms | 22160 KB | Output is correct |

8 | Correct | 1 ms | 384 KB | Output is correct |

9 | Correct | 60 ms | 5908 KB | Output is correct |

10 | Correct | 237 ms | 22136 KB | Output is correct |

11 | Correct | 239 ms | 22136 KB | Output is correct |

12 | Correct | 267 ms | 22136 KB | Output is correct |

13 | Correct | 1 ms | 512 KB | Output is correct |

14 | Incorrect | 1 ms | 384 KB | Too few ways to get from 4 to 5, should be 1 found 0 |

15 | Halted | 0 ms | 0 KB | - |

# | 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 | 512 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 | 247 ms | 22116 KB | Output is correct |

8 | Correct | 0 ms | 384 KB | Output is correct |

9 | Correct | 0 ms | 384 KB | Output is correct |

10 | Correct | 0 ms | 384 KB | Output is correct |

11 | Correct | 0 ms | 384 KB | Output is correct |

12 | Correct | 10 ms | 1280 KB | Output is correct |

13 | Correct | 237 ms | 22136 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 | 114 ms | 12152 KB | Output is correct |

18 | Correct | 1 ms | 384 KB | Output is correct |

19 | Correct | 0 ms | 384 KB | Output is correct |

20 | Correct | 61 ms | 5876 KB | Output is correct |

21 | Correct | 248 ms | 22136 KB | Output is correct |

22 | Correct | 255 ms | 22124 KB | Output is correct |

23 | Correct | 258 ms | 22132 KB | Output is correct |

24 | Correct | 236 ms | 22264 KB | Output is correct |

25 | Correct | 100 ms | 12152 KB | Output is correct |

26 | Correct | 100 ms | 12152 KB | Output is correct |

27 | Correct | 254 ms | 22136 KB | Output is correct |

28 | Correct | 243 ms | 22264 KB | Output is correct |

29 | Correct | 1 ms | 384 KB | Output is correct |

30 | Correct | 0 ms | 384 KB | Output is correct |

31 | Correct | 0 ms | 384 KB | Output is correct |

32 | Correct | 1 ms | 360 KB | Output is correct |

33 | Correct | 0 ms | 384 KB | Output is correct |

34 | Correct | 0 ms | 384 KB | Output is correct |

35 | Correct | 1 ms | 384 KB | Output is correct |

36 | Correct | 10 ms | 1280 KB | Output is correct |

37 | Correct | 241 ms | 22128 KB | Output is correct |

38 | Correct | 0 ms | 384 KB | Output is correct |

39 | Correct | 0 ms | 384 KB | Output is correct |

40 | Correct | 10 ms | 1280 KB | Output is correct |

41 | Correct | 250 ms | 22128 KB | Output is correct |

42 | Correct | 1 ms | 384 KB | Output is correct |

43 | Correct | 1 ms | 384 KB | Output is correct |

44 | Correct | 5 ms | 768 KB | Output is correct |

45 | Correct | 115 ms | 12152 KB | Output is correct |

46 | Correct | 1 ms | 384 KB | Output is correct |

47 | Correct | 0 ms | 384 KB | Output is correct |

48 | Correct | 1 ms | 384 KB | Output is correct |

49 | Correct | 64 ms | 5884 KB | Output is correct |

50 | Correct | 245 ms | 22156 KB | Output is correct |

51 | Correct | 235 ms | 22136 KB | Output is correct |

52 | Correct | 250 ms | 22132 KB | Output is correct |

53 | Correct | 97 ms | 12152 KB | Output is correct |

54 | Correct | 110 ms | 12156 KB | Output is correct |

55 | Correct | 234 ms | 22136 KB | Output is correct |

56 | Correct | 254 ms | 22100 KB | Output is correct |

57 | Correct | 96 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 | 111 ms | 12152 KB | Output is correct |

62 | Correct | 1 ms | 384 KB | Output is correct |

63 | Incorrect | 0 ms | 384 KB | Too few ways to get from 0 to 1, should be 1 found 0 |

64 | Halted | 0 ms | 0 KB | - |

# | 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 | 512 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 | 247 ms | 22116 KB | Output is correct |

8 | Correct | 0 ms | 384 KB | Output is correct |

9 | Correct | 0 ms | 384 KB | Output is correct |

10 | Correct | 0 ms | 384 KB | Output is correct |

11 | Correct | 0 ms | 384 KB | Output is correct |

12 | Correct | 10 ms | 1280 KB | Output is correct |

13 | Correct | 237 ms | 22136 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 | 114 ms | 12152 KB | Output is correct |

18 | Correct | 1 ms | 384 KB | Output is correct |

19 | Correct | 0 ms | 384 KB | Output is correct |

20 | Correct | 61 ms | 5876 KB | Output is correct |

21 | Correct | 248 ms | 22136 KB | Output is correct |

22 | Correct | 255 ms | 22124 KB | Output is correct |

23 | Correct | 258 ms | 22132 KB | Output is correct |

24 | Correct | 236 ms | 22264 KB | Output is correct |

25 | Correct | 100 ms | 12152 KB | Output is correct |

26 | Correct | 100 ms | 12152 KB | Output is correct |

27 | Correct | 254 ms | 22136 KB | Output is correct |

28 | Correct | 243 ms | 22264 KB | Output is correct |

29 | Correct | 1 ms | 384 KB | Output is correct |

30 | Correct | 0 ms | 384 KB | Output is correct |

31 | Correct | 0 ms | 384 KB | Output is correct |

32 | Correct | 1 ms | 360 KB | Output is correct |

33 | Correct | 0 ms | 384 KB | Output is correct |

34 | Correct | 0 ms | 384 KB | Output is correct |

35 | Correct | 1 ms | 384 KB | Output is correct |

36 | Correct | 10 ms | 1280 KB | Output is correct |

37 | Correct | 241 ms | 22128 KB | Output is correct |

38 | Correct | 0 ms | 384 KB | Output is correct |

39 | Correct | 0 ms | 384 KB | Output is correct |

40 | Correct | 10 ms | 1280 KB | Output is correct |

41 | Correct | 250 ms | 22128 KB | Output is correct |

42 | Correct | 1 ms | 384 KB | Output is correct |

43 | Correct | 1 ms | 384 KB | Output is correct |

44 | Correct | 5 ms | 768 KB | Output is correct |

45 | Correct | 115 ms | 12152 KB | Output is correct |

46 | Correct | 1 ms | 384 KB | Output is correct |

47 | Correct | 0 ms | 384 KB | Output is correct |

48 | Correct | 1 ms | 384 KB | Output is correct |

49 | Correct | 64 ms | 5884 KB | Output is correct |

50 | Correct | 245 ms | 22156 KB | Output is correct |

51 | Correct | 235 ms | 22136 KB | Output is correct |

52 | Correct | 250 ms | 22132 KB | Output is correct |

53 | Correct | 97 ms | 12152 KB | Output is correct |

54 | Correct | 110 ms | 12156 KB | Output is correct |

55 | Correct | 234 ms | 22136 KB | Output is correct |

56 | Correct | 254 ms | 22100 KB | Output is correct |

57 | Correct | 96 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 | 1 ms | 384 KB | Output is correct |

61 | Correct | 63 ms | 5992 KB | Output is correct |

62 | Correct | 239 ms | 22136 KB | Output is correct |

63 | Correct | 241 ms | 22268 KB | Output is correct |

64 | Correct | 260 ms | 22160 KB | Output is correct |

65 | Correct | 1 ms | 384 KB | Output is correct |

66 | Correct | 60 ms | 5908 KB | Output is correct |

67 | Correct | 237 ms | 22136 KB | Output is correct |

68 | Correct | 239 ms | 22136 KB | Output is correct |

69 | Correct | 267 ms | 22136 KB | Output is correct |

70 | Correct | 1 ms | 512 KB | Output is correct |

71 | Incorrect | 1 ms | 384 KB | Too few ways to get from 4 to 5, should be 1 found 0 |

72 | Halted | 0 ms | 0 KB | - |