답안 #755054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
755054 2023-06-09T11:08:06 Z sofija6 슈퍼트리 잇기 (IOI20_supertrees) C++14
56 / 100
197 ms 25140 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define MAXN 1010
using namespace std;
int d[MAXN];
int Root(int p)
{
    while (d[p]!=p)
    {
        d[p]=d[d[p]];
        p=d[p];
    }
    return p;
}
void Join(int p,int q)
{
    d[Root(p)]=d[Root(q)];
}
int construct(std::vector<std::vector<int>> p) {
    int n=p.size();
    for (int i=0;i<n;i++)
    {
        d[i]=i;
        for (int j=0;j<n;j++)
        {
            if (p[i][j]==3 || p[i][j]!=p[j][i])
                return 0;
        }
    }
    vector<int> v[n+2];
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<n;j++)
        {
            if (p[i][j]==1)
                Join(i,j);
        }
    }
    vector<vector<int> > b;
    b.resize(n);
    for (int i=0;i<n;i++)
        b[i].resize(n);
    for (int i=0;i<n;i++)
    {
        if (i==Root(i))
            continue;
        b[i][Root(i)]=1;
        b[Root(i)][i]=1;
    }
    bool cyc[n+2][n+2];
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<n;j++)
            cyc[i][j]=false;
    }
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<n;j++)
        {
            if (p[i][j]==2)
                cyc[Root(i)][Root(j)]=true;
        }
    }
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<n;j++)
        {
            if ((!p[i][j] && (Root(i)==Root(j) || cyc[Root(i)][Root(j)])) || (p[i][j]==1 && cyc[Root(i)][Root(j)]))
                return 0;
        }
    }
    bool vis[n+2]={false};
    for (int i=0;i<n;i++)
    {
        if (vis[i])
            continue;
        set<int> s;
        vector<int> v;
        int cur=i;
        while (true)
        {
            s.insert(cur);
            v.push_back(cur);
            vis[cur]=true;
            bool next=false;
            for (int j=cur+1;j<n;j++)
            {
                if (cyc[cur][j])
                {
                    cur=j;
                    next=true;
                    break;
                }
            }
            if (!next)
                break;
        }
        if (s.size()==2)
            return 0;
        if (s.size()==1)
        {
            if (cyc[cur][cur])
                return 0;
            continue;
        }
        for (int i=0;i<v.size()-1;i++)
        {
            b[v[i]][v[i+1]]=1;
            b[v[i+1]][v[i]]=1;
        }
        b[v[v.size()-1]][v[0]]=1;
        b[v[0]][v[v.size()-1]]=1;
    }
    build(b);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:106:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for (int i=0;i<v.size()-1;i++)
      |                      ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 178 ms 24944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 178 ms 24944 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 13 ms 1236 KB Output is correct
13 Correct 177 ms 24952 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 98 ms 14972 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 46 ms 6476 KB Output is correct
21 Correct 188 ms 24964 KB Output is correct
22 Correct 184 ms 24992 KB Output is correct
23 Correct 197 ms 24952 KB Output is correct
24 Correct 178 ms 24956 KB Output is correct
25 Correct 106 ms 15104 KB Output is correct
26 Correct 77 ms 14972 KB Output is correct
27 Correct 184 ms 24936 KB Output is correct
28 Correct 179 ms 24952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 8 ms 1316 KB Output is correct
9 Correct 176 ms 24968 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 182 ms 24956 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Incorrect 1 ms 300 KB Answer gives possible 1 while actual possible 0
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 48 ms 6424 KB Output is correct
5 Correct 187 ms 24952 KB Output is correct
6 Correct 185 ms 24968 KB Output is correct
7 Correct 190 ms 25020 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 45 ms 6448 KB Output is correct
10 Correct 189 ms 25040 KB Output is correct
11 Correct 185 ms 24952 KB Output is correct
12 Correct 187 ms 25140 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 44 ms 6392 KB Output is correct
17 Correct 177 ms 24952 KB Output is correct
18 Correct 192 ms 24968 KB Output is correct
19 Correct 185 ms 25092 KB Output is correct
20 Correct 176 ms 25008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 178 ms 24944 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 13 ms 1236 KB Output is correct
13 Correct 177 ms 24952 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 98 ms 14972 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 46 ms 6476 KB Output is correct
21 Correct 188 ms 24964 KB Output is correct
22 Correct 184 ms 24992 KB Output is correct
23 Correct 197 ms 24952 KB Output is correct
24 Correct 178 ms 24956 KB Output is correct
25 Correct 106 ms 15104 KB Output is correct
26 Correct 77 ms 14972 KB Output is correct
27 Correct 184 ms 24936 KB Output is correct
28 Correct 179 ms 24952 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 300 KB Output is correct
33 Correct 0 ms 300 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1316 KB Output is correct
37 Correct 176 ms 24968 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 182 ms 24956 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Incorrect 1 ms 300 KB Answer gives possible 1 while actual possible 0
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 178 ms 24944 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 13 ms 1236 KB Output is correct
13 Correct 177 ms 24952 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 98 ms 14972 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 46 ms 6476 KB Output is correct
21 Correct 188 ms 24964 KB Output is correct
22 Correct 184 ms 24992 KB Output is correct
23 Correct 197 ms 24952 KB Output is correct
24 Correct 178 ms 24956 KB Output is correct
25 Correct 106 ms 15104 KB Output is correct
26 Correct 77 ms 14972 KB Output is correct
27 Correct 184 ms 24936 KB Output is correct
28 Correct 179 ms 24952 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 300 KB Output is correct
33 Correct 0 ms 300 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1316 KB Output is correct
37 Correct 176 ms 24968 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 182 ms 24956 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Incorrect 1 ms 300 KB Answer gives possible 1 while actual possible 0
44 Halted 0 ms 0 KB -