# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1090025 | 2024-09-17T15:14:01 Z | onlk97 | Connecting Supertrees (IOI20_supertrees) | C++14 | 1 ms | 348 KB |
#include "supertrees.h" #include <vector> #include <bits/stdc++.h> using namespace std; struct DSU{ vector <int> dsu; void init(int n){ dsu.clear(); for (int i=0; i<=n; i++) dsu.push_back(i); } int prt(int n){ if (dsu[n]==n) return n; return dsu[n]=prt(dsu[n]); } void unn(int u,int v){ dsu[prt(u)]=dsu[prt(v)]; } }; int construct(vector <vector <int> > p){ int n=p.size(); DSU d; d.init(n); vector <vector <int> > op(n,vector <int>(n,0)); for (int i=0; i<n; i++){ for (int j=i+1; j<n; j++){ if (p[i][j]==1){ d.unn(i,j); op[i][j]=1; op[j][i]=1; } if (p[i][j]==3) return 0; } } for (int i=0; i<n; i++){ for (int j=i+1; j<n; j++){ if ((p[i][j]==1)!=(d.prt(i)==d.prt(j))) return 0; } } for (int i=0; i<n; i++){ if (p[i]!=p[d.prt(i)]) return 0; } bool done[n]; for (int i=0; i<n; i++) done[i]=0; for (int i=0; i<n; i++){ if (d.prt(i)!=i||done[i]) continue; set <int> s; s.insert(d.prt(i)); for (int j=i+1; j<n; j++){ if (p[i][j]==2) s.insert(d.prt(j)); } if (s.size()<3) return 0; vector <int> vec; for (int j:s) vec.push_back(j); for (int j=0; j<s.size(); j++){ op[vec[j]][vec[(j+1)%s.size()]]=1; op[vec[(j+1)%s.size()]][vec[j]]=1; } for (int j:vec){ done[j]=1; for (int k=0; k<n; k++){ if (p[j][k]==2&&s.find(d.prt(k))==s.end()) return 0; } } } build(op); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 344 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 344 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 344 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 344 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |