Submission #864743

# Submission time Handle Problem Language Result Execution time Memory
864743 2023-10-23T14:09:34 Z andrei_boaca Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
155 ms 30292 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;

int n;
vector<vector<int>> adj;
vector<int> muchii[1005];
int comp[1005],nrcomp;
vector<int> nodes;
void dfs(int nod)
{
    comp[nod]=nrcomp;
    nodes.push_back(nod);
    for(int i:muchii[nod])
        if(!comp[i])
            dfs(i);
}
int construct(std::vector<std::vector<int>> p)
{
    n=p.size();
    adj.resize(n);
    for(int i=0;i<n;i++)
        adj[i].resize(n);
    bool sub1=1;
    bool sub2=1;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            sub1&=(p[i][j]<=1);
            sub2&=(p[i][j]==0||p[i][j]==2);
        }
    if(sub1||sub2)
    {
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(p[i][j]==1)
                {
                    muchii[i].push_back(j);
                    muchii[j].push_back(i);
                }
        for(int i=0;i<n;i++)
            if(comp[i]==0)
            {
                nrcomp++;
                nodes.clear();
                dfs(i);
                for(int j=1;j<nodes.size();j++)
                {
                    int a=nodes[j-1];
                    int b=nodes[j];
                    adj[a][b]=adj[b][a]=1;
                }
                if(sub2)
                {
                    int a=nodes[0];
                    int b=nodes.back();
                    if(a!=b)
                    {
                        adj[a][b]=1;
                        adj[b][a]=1;
                    }
                }
            }
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            {
                if(p[i][j]==0&&comp[i]==comp[j])
                    return 0;
                if(p[i][j]>0&&comp[i]!=comp[j])
                    return 0;
            }
        build(adj);
        return 1;
    }
	return 0;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:49:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |                 for(int j=1;j<nodes.size();j++)
      |                             ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1740 KB Output is correct
7 Correct 152 ms 30292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1740 KB Output is correct
7 Correct 152 ms 30292 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 8 ms 1116 KB Output is correct
13 Correct 145 ms 22028 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 71 ms 18004 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 37 ms 5956 KB Output is correct
21 Correct 149 ms 23120 KB Output is correct
22 Correct 148 ms 22056 KB Output is correct
23 Correct 155 ms 26192 KB Output is correct
24 Correct 142 ms 22060 KB Output is correct
25 Correct 60 ms 13344 KB Output is correct
26 Correct 58 ms 12328 KB Output is correct
27 Correct 154 ms 28212 KB Output is correct
28 Correct 154 ms 22220 KB Output is correct
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1740 KB Output is correct
7 Correct 152 ms 30292 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 8 ms 1116 KB Output is correct
13 Correct 145 ms 22028 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 71 ms 18004 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 37 ms 5956 KB Output is correct
21 Correct 149 ms 23120 KB Output is correct
22 Correct 148 ms 22056 KB Output is correct
23 Correct 155 ms 26192 KB Output is correct
24 Correct 142 ms 22060 KB Output is correct
25 Correct 60 ms 13344 KB Output is correct
26 Correct 58 ms 12328 KB Output is correct
27 Correct 154 ms 28212 KB Output is correct
28 Correct 154 ms 22220 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 -
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1740 KB Output is correct
7 Correct 152 ms 30292 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 8 ms 1116 KB Output is correct
13 Correct 145 ms 22028 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 71 ms 18004 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 37 ms 5956 KB Output is correct
21 Correct 149 ms 23120 KB Output is correct
22 Correct 148 ms 22056 KB Output is correct
23 Correct 155 ms 26192 KB Output is correct
24 Correct 142 ms 22060 KB Output is correct
25 Correct 60 ms 13344 KB Output is correct
26 Correct 58 ms 12328 KB Output is correct
27 Correct 154 ms 28212 KB Output is correct
28 Correct 154 ms 22220 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 -