Submission #300339

#TimeUsernameProblemLanguageResultExecution timeMemory
300339fpc_coderConnecting Supertrees (IOI20_supertrees)C++17
19 / 100
248 ms22264 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; int construct(vector<vector<int>> p) { vector<vector<int>> b(p.size(), vector<int>(p.size(), 0)); int n = (int) p.size(); vector<int> par(n, -1); vector<bool> vis(n, false); for (int i = 0; i < n; i++) { vector<int> v; if (!vis[i]) { for (int j = 0; j < n; j++) { if (p[i][j] == 2) { v.push_back(j); vis[i] = true; vis[j] = true; } } if ((int) v.size() == 1) return 0; if ((int) v.size() >= 2) { for (int j = 0; j + 1 < (int) v.size(); j++) { b[v[j]][v[j + 1]] = 1; b[v[j + 1]][v[j]] = 1; } b[v[0]][i] = 1; b[i][v[0]] = 1; b[v[(int) v.size() - 1]][i] = 1; b[i][v[(int) v.size() - 1]] = 1; } } } for (int i = 0; i < n; i++) par[i] = i; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (p[i][j] == 2) par[j] = i; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (par[i] == par[j] && p[i][j] == 0) return 0; if (par[i] != par[j] && p[i][j] == 2) return 0; } } build(b); return 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...