Submission #521244

# Submission time Handle Problem Language Result Execution time Memory
521244 2022-02-01T09:43:56 Z oneloveforever Connecting Supertrees (IOI20_supertrees) C++14
21 / 100
232 ms 24216 KB
#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define ll long long
struct DSU
{
    int n;
    vector<int>trace;
    DSU(int _n=0)
    {
        n=_n;
        trace.resize(n+7);
        iota(trace.begin(),trace.end(),0);
    }
    int get(int x)
    {
        return trace[x]==x?trace[x]:trace[x]=get(trace[x]);
    }
    void connect(int x,int y)
    {
        int u=get(x);
        int v=get(y);
        if(u==v)return ;
        trace[v]=u;
    }
};
int construct(vector<vector<int> >p)
{
    int n=p.size();
    DSU only(n);
    DSU can(n);
    for(int i=0;i<=n-1;i++)
    {
        for(int j=0;j<=n-1;j++)if(p[i][j]==3)return 0;
    }
    vector<vector<int> >b(n,vector<int>(n,0));
    for(int i=0;i<=n-1;i++)
    {
        for(int j=i+1;j<=n-1;j++)
        {
            if(p[i][j]==1)only.connect(i,j);
            if(p[i][j])can.connect(i,j);
        }
    }
    for(int i=0;i<=n-1;i++)
    {
        if(can.get(i)!=i)continue;
        vector<int>q;
        for(int node=0;node<=n-1;node++)
        {
            if(can.get(node)==i&&only.get(node)==node)q.push_back(node);
        }
        if((int)q.size()==1)continue;
        if((int)q.size()==2)return 0;
        for(int node=0;node<=q.size()-2;node++)
        {
            int node_x=q[node];
            int node_y=q[(node+1)%n];
            b[node_x][node_y]=1;
            b[node_y][node_x]=1;
        }
    }
    for(int i=0;i<=n-1;i++)if(only.get(i)!=i)
    {
        int node=only.get(i);
        b[node][i]=b[i][node]=1;
    }
    for(int i=0;i<=n-1;i++)
    {
        for(int j=i+1;j<=n-1;j++)
        {
            if(only.get(i)==only.get(j))
            {
                if(p[i][j]!=1)return 0;
            }
            else if(can.get(i)==can.get(j))
            {
                if(p[i][j]!=2)return 0;
            }
            else
            {
                if(p[i][j])return 0;
            }
        }
    }
    build(b);
    return 1;


}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:55:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int node=0;node<=q.size()-2;node++)
      |                        ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 192 ms 24044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 192 ms 24044 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 9 ms 1192 KB Output is correct
13 Correct 186 ms 23916 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 816 KB Output is correct
17 Correct 83 ms 14072 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 48 ms 6256 KB Output is correct
21 Correct 189 ms 24216 KB Output is correct
22 Correct 201 ms 23876 KB Output is correct
23 Correct 198 ms 24072 KB Output is correct
24 Correct 217 ms 23916 KB Output is correct
25 Correct 83 ms 13988 KB Output is correct
26 Correct 72 ms 14060 KB Output is correct
27 Correct 195 ms 24004 KB Output is correct
28 Correct 232 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Too few ways to get from 0 to 1, should be 2 found 1
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Incorrect 1 ms 204 KB Too few ways to get from 0 to 1, should be 2 found 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 192 ms 24044 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 9 ms 1192 KB Output is correct
13 Correct 186 ms 23916 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 816 KB Output is correct
17 Correct 83 ms 14072 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 48 ms 6256 KB Output is correct
21 Correct 189 ms 24216 KB Output is correct
22 Correct 201 ms 23876 KB Output is correct
23 Correct 198 ms 24072 KB Output is correct
24 Correct 217 ms 23916 KB Output is correct
25 Correct 83 ms 13988 KB Output is correct
26 Correct 72 ms 14060 KB Output is correct
27 Correct 195 ms 24004 KB Output is correct
28 Correct 232 ms 23916 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 292 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Incorrect 1 ms 204 KB Too few ways to get from 0 to 1, should be 2 found 1
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 192 ms 24044 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 9 ms 1192 KB Output is correct
13 Correct 186 ms 23916 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 816 KB Output is correct
17 Correct 83 ms 14072 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 48 ms 6256 KB Output is correct
21 Correct 189 ms 24216 KB Output is correct
22 Correct 201 ms 23876 KB Output is correct
23 Correct 198 ms 24072 KB Output is correct
24 Correct 217 ms 23916 KB Output is correct
25 Correct 83 ms 13988 KB Output is correct
26 Correct 72 ms 14060 KB Output is correct
27 Correct 195 ms 24004 KB Output is correct
28 Correct 232 ms 23916 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 292 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Incorrect 1 ms 204 KB Too few ways to get from 0 to 1, should be 2 found 1
34 Halted 0 ms 0 KB -