# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1007386 | 2024-06-24T18:36:00 Z | Ahmed57 | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 348 KB |
#include "bits/stdc++.h" #include "supertrees.h" using namespace std; int pr[100001]; int find(int x){ if(x==pr[x])return x; return pr[x] = find(pr[x]); } void mergegroup(int a,int b){ a = find(a); b = find(b); if(a==b)return ; pr[a] = b; } int pr2[100001]; int find2(int x){ if(x==pr2[x])return x; return pr2[x] = find2(pr2[x]); } void mergegroup2(int a,int b){ a = find2(a); b = find2(b); if(a==b)return ; pr2[a] = b; } int construct(vector<vector<int>> p){ int n = p.size(); vector<vector<int>> B; vector<int> x(n,0); for(int i = 0;i<n;i++){ B.push_back(x); } //phase 1 for(int i = 0;i<n;i++){ pr[i] = i; } for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ if(p[i][j]){ mergegroup(i,j); } } } for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ if(find(i)==find(j)){ if(p[i][j]==0){ return 0; } }else{ if(p[i][j]){ return 0; } } } } //phase 2 for(int i = 0;i<n;i++){ pr2[i] = i; } for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ if(p[i][j]==1){ mergegroup2(i,j); } } } for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ if(find2(i)==find2(j)){ if(p[i][j]!=1){ return 0; } }else{ if(p[i][j]==1){ return 0; } } } } for(int i = 0;i<n;i++){ if(i==find(i)){ vector<int> lol; for(int j = 0;j<n;j++){ if(find(i)==find(j)){ lol.push_back(j); } } vector<int> ror[n]; for(int j:lol){ ror[find2(j)].push_back(j); } vector<int> nah; for(int j = 0;j<n;j++){ if(ror[j].size()){ nah.push_back(j); } for(int e = 1;e<ror[j].size();e++){ B[ror[j][e-1]][ror[j][e]]=1; B[ror[j][e]][ror[j][e-1]]=1; } } for(int j = 0;j<nah.size();j++){ int a = nah[j] , b = nah[(j+1)%nah.size()]; B[a][b] = 1; B[b][a] = 1; } } } build(B); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | b[0][0] is not 0 |
2 | Halted | 0 ms | 0 KB | - |