답안 #833746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833746 2023-08-22T08:26:37 Z andrey27_sm 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
165 ms 32076 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
mt19937 rnd(time(0));
vector<int> same_tree[1000];
vector<int> same_component[1000];
vector<int> cyc[1000];
int p[1000];
int pr(int v){
    if(p[v] == v) return v;
    return p[v] = pr(p[v]);
}
void un(int v,int u){
    v = pr(v);
    u = pr(u);
    if(v == u) return;
    if(rnd()&1) swap(u,v);
    p[u] = v;
}
bool used[1000];
int construct(vector<vector<int>> p) {
    int n = p.size();
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if(p[i][j] == 3) return 0;
            if(p[i][j] >= 1) same_component[i].push_back(j);
            if(p[i][j] == 1) same_tree[i].push_back(j);
        }
    }
    for (int i = 0; i < n; ++i)
    {
        ::p[i] = i;
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if(p[i][j]) un(i,j);
        }
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if(p[i][j] == 0 and pr(i) == pr(j)) return 0;
        }
    }


    /*for (int i = 0; i < n; ++i)
    {
        ::p[i] = i;
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if(p[i][j] == 1) un(i,j);
        }
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if(p[i][j] != 1 and pr(i) == pr(j)) return 0;
        }
    }*/
    vector<vector<int>> graph(n,vector<int>(n));
    for (int i = 0; i < n; ++i)
    {
        sort(same_tree[i].begin(),same_tree[i].end());
        if(used[i]) continue;
        used[i] = 1;
        for(auto e:same_tree[i]){
            if(e == i) continue;
            used[e] = 1;
            graph[i][e] = 1;
            graph[e][i] = 1;
        }
    }
    for (int i = 0; i < n; ++i)
    {
        used[i] = 0;
    }
    for (int i = 0; i < n; ++i)
    {
        if(used[i]) continue;
        used[i] = 1;
        set<int> C;
        for(auto e:same_component[i]){
            used[e] = 1;
            C.insert(same_tree[e][0]);
        }
        for(auto e:C) cyc[i].push_back(e);
        if(C.size() > 1) cyc[i].push_back(cyc[i][0]);
        for (int j = 0; j+1 < cyc[i].size(); ++j)
        {
            graph[cyc[i][j]][cyc[i][j+1]] = 1;
            graph[cyc[i][j+1]][cyc[i][j]] = 1;
        }
    }
    build(graph);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:98:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |         for (int j = 0; j+1 < cyc[i].size(); ++j)
      |                         ~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 376 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1676 KB Output is correct
7 Correct 159 ms 32076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 376 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1676 KB Output is correct
7 Correct 159 ms 32076 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 6 ms 1364 KB Output is correct
13 Correct 143 ms 23560 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 100 ms 15044 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 36 ms 6400 KB Output is correct
21 Correct 149 ms 25076 KB Output is correct
22 Correct 146 ms 24056 KB Output is correct
23 Correct 158 ms 28016 KB Output is correct
24 Correct 145 ms 24112 KB Output is correct
25 Correct 64 ms 11244 KB Output is correct
26 Correct 61 ms 10188 KB Output is correct
27 Correct 162 ms 30144 KB Output is correct
28 Correct 144 ms 24140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 380 KB Output is correct
2 Correct 1 ms 428 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 380 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 38 ms 6336 KB Output is correct
5 Correct 148 ms 25108 KB Output is correct
6 Correct 165 ms 24084 KB Output is correct
7 Correct 159 ms 28112 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 37 ms 6344 KB Output is correct
10 Correct 152 ms 24612 KB Output is correct
11 Correct 145 ms 24052 KB Output is correct
12 Correct 153 ms 27160 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 37 ms 6336 KB Output is correct
17 Correct 147 ms 24524 KB Output is correct
18 Correct 152 ms 24784 KB Output is correct
19 Correct 148 ms 24264 KB Output is correct
20 Correct 142 ms 24140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 376 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1676 KB Output is correct
7 Correct 159 ms 32076 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 6 ms 1364 KB Output is correct
13 Correct 143 ms 23560 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 100 ms 15044 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 36 ms 6400 KB Output is correct
21 Correct 149 ms 25076 KB Output is correct
22 Correct 146 ms 24056 KB Output is correct
23 Correct 158 ms 28016 KB Output is correct
24 Correct 145 ms 24112 KB Output is correct
25 Correct 64 ms 11244 KB Output is correct
26 Correct 61 ms 10188 KB Output is correct
27 Correct 162 ms 30144 KB Output is correct
28 Correct 144 ms 24140 KB Output is correct
29 Correct 1 ms 380 KB Output is correct
30 Correct 1 ms 428 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Incorrect 1 ms 340 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 376 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1676 KB Output is correct
7 Correct 159 ms 32076 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 6 ms 1364 KB Output is correct
13 Correct 143 ms 23560 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 100 ms 15044 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 36 ms 6400 KB Output is correct
21 Correct 149 ms 25076 KB Output is correct
22 Correct 146 ms 24056 KB Output is correct
23 Correct 158 ms 28016 KB Output is correct
24 Correct 145 ms 24112 KB Output is correct
25 Correct 64 ms 11244 KB Output is correct
26 Correct 61 ms 10188 KB Output is correct
27 Correct 162 ms 30144 KB Output is correct
28 Correct 144 ms 24140 KB Output is correct
29 Correct 1 ms 380 KB Output is correct
30 Correct 1 ms 428 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Incorrect 1 ms 340 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -