답안 #955411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955411 2024-03-30T11:52:35 Z Nelt 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
184 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 (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

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++)
      |                    ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 8 ms 3420 KB Output is correct
7 Correct 166 ms 30000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 8 ms 3420 KB Output is correct
7 Correct 166 ms 30000 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 3536 KB Output is correct
13 Correct 158 ms 31020 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 3164 KB Output is correct
17 Correct 84 ms 22048 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 39 ms 10528 KB Output is correct
21 Correct 168 ms 31964 KB Output is correct
22 Correct 157 ms 31808 KB Output is correct
23 Correct 184 ms 32080 KB Output is correct
24 Correct 157 ms 31288 KB Output is correct
25 Correct 64 ms 22100 KB Output is correct
26 Correct 63 ms 21844 KB Output is correct
27 Correct 166 ms 32084 KB Output is correct
28 Correct 152 ms 31132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 8 ms 3420 KB Output is correct
7 Correct 166 ms 30000 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 3536 KB Output is correct
13 Correct 158 ms 31020 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 3164 KB Output is correct
17 Correct 84 ms 22048 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 39 ms 10528 KB Output is correct
21 Correct 168 ms 31964 KB Output is correct
22 Correct 157 ms 31808 KB Output is correct
23 Correct 184 ms 32080 KB Output is correct
24 Correct 157 ms 31288 KB Output is correct
25 Correct 64 ms 22100 KB Output is correct
26 Correct 63 ms 21844 KB Output is correct
27 Correct 166 ms 32084 KB Output is correct
28 Correct 152 ms 31132 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 8 ms 3420 KB Output is correct
7 Correct 166 ms 30000 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 3536 KB Output is correct
13 Correct 158 ms 31020 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 3164 KB Output is correct
17 Correct 84 ms 22048 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 39 ms 10528 KB Output is correct
21 Correct 168 ms 31964 KB Output is correct
22 Correct 157 ms 31808 KB Output is correct
23 Correct 184 ms 32080 KB Output is correct
24 Correct 157 ms 31288 KB Output is correct
25 Correct 64 ms 22100 KB Output is correct
26 Correct 63 ms 21844 KB Output is correct
27 Correct 166 ms 32084 KB Output is correct
28 Correct 152 ms 31132 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -