# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731925 | 2023-04-28T06:59:59 Z | TheSahib | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 308 KB |
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int MAX = 1005; int par[MAX]; int find_set(int v){ if(par[v] < 0) return v; return par[v] = find_set(par[v]); } bool unite(int u, int v){ u = find_set(u); v = find_set(v); if(u == v) return false; par[u] += par[v]; par[v] = u; return true; } int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> ans(n, vector<int>(n)); memset(par, -1, sizeof(par)); vector<bool> except(n, 0); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if(p[i][j] == 1){ except[i] = 1; ans[i][j] = 1; ans[j][i] = 1; } } } for (int i = 0; i < n; i++) { if(except[i]) continue; for (int j = 0; j < n; j++) { if(except[j]) continue; if(p[i][j] == 2){ unite(i, j); } } } vector<int> comps[MAX]; for (int i = 0; i < n; i++) { if(except[i]) continue; comps[find_set(i)].push_back(i); } for(auto& v:comps){ for (int i = 0; i < v.size(); i++) { if(i != 0){ ans[v[i]][v[i - 1]] = 1; } if(i != v.size() - 1){ ans[v[i]][v[i + 1]] = 1; } } if(v.size() > 1){ ans[v.front()][v.back()] = 1; ans[v.back()][v.front()] = 1; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(p[i][j] == 1 && unite(i, j)){ ans[i][j] = 1; ans[j][i] = 1; } } } build(ans); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Incorrect | 1 ms | 296 KB | Answer gives possible 1 while actual possible 0 |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Too many ways to get from 1 to 4, should be 1 found no less than 2 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 | Halted | 0 ms | 0 KB | - |