답안 #864745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864745 2023-10-23T14:11:39 Z andrei_boaca 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
187 ms 30504 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||i==j);
        }
    if(sub1||sub2)
    {
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(p[i][j]!=0)
                {
                    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++)
      |                             ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 Correct 0 ms 344 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 156 ms 30256 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 Correct 0 ms 344 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 156 ms 30256 KB Output is correct
8 Correct 0 ms 344 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 1116 KB Output is correct
13 Correct 145 ms 22068 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 72 ms 17896 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 37 ms 5980 KB Output is correct
21 Correct 154 ms 23112 KB Output is correct
22 Correct 145 ms 22240 KB Output is correct
23 Correct 157 ms 26196 KB Output is correct
24 Correct 145 ms 22060 KB Output is correct
25 Correct 62 ms 13348 KB Output is correct
26 Correct 59 ms 12120 KB Output is correct
27 Correct 180 ms 28204 KB Output is correct
28 Correct 148 ms 22228 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 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 39 ms 6412 KB Output is correct
5 Correct 167 ms 25232 KB Output is correct
6 Correct 175 ms 24144 KB Output is correct
7 Correct 163 ms 28064 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 36 ms 6300 KB Output is correct
10 Correct 152 ms 25424 KB Output is correct
11 Correct 160 ms 24144 KB Output is correct
12 Correct 187 ms 30504 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Incorrect 0 ms 460 KB Answer gives possible 0 while actual possible 1
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 0 ms 344 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 156 ms 30256 KB Output is correct
8 Correct 0 ms 344 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 1116 KB Output is correct
13 Correct 145 ms 22068 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 72 ms 17896 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 37 ms 5980 KB Output is correct
21 Correct 154 ms 23112 KB Output is correct
22 Correct 145 ms 22240 KB Output is correct
23 Correct 157 ms 26196 KB Output is correct
24 Correct 145 ms 22060 KB Output is correct
25 Correct 62 ms 13348 KB Output is correct
26 Correct 59 ms 12120 KB Output is correct
27 Correct 180 ms 28204 KB Output is correct
28 Correct 148 ms 22228 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 0 ms 344 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 156 ms 30256 KB Output is correct
8 Correct 0 ms 344 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 1116 KB Output is correct
13 Correct 145 ms 22068 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 72 ms 17896 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 37 ms 5980 KB Output is correct
21 Correct 154 ms 23112 KB Output is correct
22 Correct 145 ms 22240 KB Output is correct
23 Correct 157 ms 26196 KB Output is correct
24 Correct 145 ms 22060 KB Output is correct
25 Correct 62 ms 13348 KB Output is correct
26 Correct 59 ms 12120 KB Output is correct
27 Correct 180 ms 28204 KB Output is correct
28 Correct 148 ms 22228 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -