Submission #955410

# Submission time Handle Problem Language Result Execution time Memory
955410 2024-03-30T11:50:50 Z Nelt Connecting Supertrees (IOI20_supertrees) C++17
11 / 100
171 ms 32084 KB
#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 (Union(i, 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

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 time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 3556 KB Output is correct
7 Correct 171 ms 32084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 3556 KB Output is correct
7 Correct 171 ms 32084 KB Output is correct
8 Incorrect 1 ms 348 KB Answer gives possible 0 while actual possible 1
9 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 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 3556 KB Output is correct
7 Correct 171 ms 32084 KB Output is correct
8 Incorrect 1 ms 348 KB Answer gives possible 0 while actual possible 1
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 3556 KB Output is correct
7 Correct 171 ms 32084 KB Output is correct
8 Incorrect 1 ms 348 KB Answer gives possible 0 while actual possible 1
9 Halted 0 ms 0 KB -