Submission #955411

#TimeUsernameProblemLanguageResultExecution timeMemory
955411NeltConnecting Supertrees (IOI20_supertrees)C++17
21 / 100
184 ms32084 KiB
#include "supertrees.h" #include <bits/stdc++.h> #define ll long long #define endl "\n" using namespace std; const ll N = 1005; ll dsu[N]; ll repr(ll x) { return dsu[x] < 0 ? x : dsu[x] = repr(dsu[x]); } bool Union(ll x, ll y) { x = repr(x), y = repr(y); if (x == y) return false; if (dsu[x] < dsu[y]) swap(x, y); dsu[y] += dsu[x]; dsu[x] = y; return true; } vector<int> g[N]; ll cnt[N][N]; bool used[N]; void dfs(ll v, ll st) { cnt[v][st]++; used[v] = 1; for (ll to : g[v]) if (!used[to]) dfs(to, st); used[v] = 0; } int construct(vector<vector<int>> p) { ll n = p.size(); vector<vector<int>> ans(n, vector<int>(n, 0)); for (ll i = 0; i < n; i++) for (ll j = 0; j < n; j++) if (p[i][j] == 3) return false; for (ll i = 0; i < n; i++) dsu[i] = -1; for (ll i = 0; i < n; i++) for (ll j = 0; j < n; j++) if (p[i][j] == 1) Union(i, j); vector<int> v[n]; for (ll i = 0; i < n; i++) v[repr(i)].push_back(i); vector<int> check; for (ll i = 0; i < n; i++) { if (!v[i].empty()) check.push_back(i); for (ll j = 0; j + 1 < v[i].size(); j++) ans[v[i][j]][v[i][j + 1]] = ans[v[i][j + 1]][v[i][j]] = 1, g[v[i][j]].push_back(v[i][j + 1]), g[v[i][j + 1]].push_back(v[i][j]); } for (ll i = 0; i < n; i++) dsu[i] = -1; for (ll i = 0; i < check.size(); i++) for (ll j = 0; j < check.size(); j++) if (p[check[i]][check[j]] == 2 and Union(check[i], check[j])) ans[check[i]][check[j]] = ans[check[j]][check[i]] = 1, g[check[i]].push_back(check[j]), g[check[j]].push_back(check[i]); for (ll i = 0; i < n; i++) dfs(i, i); for (ll i = 0; i < n; i++) for (ll j = 0; j < n; j++) if (cnt[i][j] != p[i][j]) return false; build(ans); return true; } /* */

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:57:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for (ll j = 0; j + 1 < v[i].size(); j++)
      |                        ~~~~~~^~~~~~~~~~~~~
supertrees.cpp:62:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (ll i = 0; i < check.size(); i++)
      |                    ~~^~~~~~~~~~~~~~
supertrees.cpp:63:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for (ll j = 0; j < check.size(); j++)
      |                    ~~^~~~~~~~~~~~~~
#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...