Submission #968774

#TimeUsernameProblemLanguageResultExecution timeMemory
968774beabossConnecting Supertrees (IOI20_supertrees)C++14
11 / 100
175 ms27948 KiB
// Source:https://ioinformatics.org/files/ioi2020problem2.pdf // #include "supertrees.h" #include "bits/stdc++.h" using namespace std; #define s second #define f first #define pb push_back typedef long long ll; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef vector<int> vi; #define FOR(i, a, b) for (int i = (a); i<b; i++) bool ckmin(int& a, int b){ return b < a ? a = b, true : false; } bool ckmax(int& a, int b){ return b > a ? a = b, true : false; } vector<vi> pth; vector<vi> sol; int n; vector<bool> vis; bool works=true; vector<vi> p; void solve(vi here) { // cout << 'd' << endl; vi cyc; vi ncyc; for (auto i: here) { bool fail=true; for (auto j: here) { if (i != j && p[i][j] != 2) { fail=false; } } if (!fail) ncyc.pb(i); else cyc.pb(i); } for (auto i: ncyc) { for (auto j: ncyc) { if (p[i][j] != 1) works=false; // cout << i << j << p[i][j] << endl; } } int chosen; if (ncyc.size()) { chosen = ncyc.back(); ncyc.pop_back(); } // cout << cyc.size() << endl; FOR(i, 0, ((int) cyc.size()) - 1) { // cout << cyc[i] << endl; sol[cyc[i]][cyc[i + 1]] = 1; sol[cyc[i + 1]][cyc[i]] = 1; } // cout << 'd' << endl; if (cyc.size() && ncyc.size()) { sol[chosen][cyc[0]]=1; sol[cyc[0]][chosen]=1; sol[chosen][cyc[cyc.size() - 1]]=1; sol[cyc[cyc.size() - 1]][chosen]=1; } if (ncyc.size()) { sol[ncyc[0]][chosen] = 1; sol[chosen][ncyc[0]] = 1; FOR(i, 0, ncyc.size() - 1) { sol[ncyc[i]][ncyc[i + 1]] = 1; sol[ncyc[i + 1]][ncyc[i]] = 1; } } } // void build(vector<vi> t) { // for (auto val: t) { // for (auto j: val) { // cout << j << ' '; // } // cout << endl; // } // } int construct(vector<vi> P) { n = P.size(); p = P; sol = vector<vi>(n, vi(n, 0)); vis.resize(n); FOR(i, 0, n) { if (!vis[i]) { vi here; FOR(j, 0, n) { if (p[i][j]) { vis[j]=true; here.pb(j); } } // cout << i << endl; solve(here); } } if (!works) return 0; build(sol); return 1; } // int main() { // ios::sync_with_stdio(false); // cin.tie(nullptr); // // cout << construct({{1, 1, 2, 2}, {1, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}}) << endl; // cout << construct({{1, 1}, {1, 1}}) << endl; // }

Compilation message (stderr)

supertrees.cpp: In function 'void solve(vi)':
supertrees.cpp:19:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 | #define FOR(i, a, b) for (int i = (a); i<b; i++)
......
   81 |   FOR(i, 0, ncyc.size() - 1) {
      |       ~~~~~~~~~~~~~~~~~~~~~              
supertrees.cpp:81:3: note: in expansion of macro 'FOR'
   81 |   FOR(i, 0, ncyc.size() - 1) {
      |   ^~~
supertrees.cpp:71:13: warning: 'chosen' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |   sol[chosen][cyc[0]]=1;
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...