답안 #842027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
842027 2023-09-02T10:20:42 Z 8pete8 슈퍼트리 잇기 (IOI20_supertrees) C++17
96 / 100
169 ms 23804 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include "supertrees.h"
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define pb push_back
#define all(x) x.begin(),x.end()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int mxn=2*1e3,mod=998244353,lg=42,root=80,inf=1e9;
void setIO(string name) {
	ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
int last[mxn+10],first[mxn+10];
struct dsu{
    int pa[mxn+10],sz[mxn+10];
    void init(){for(int i=0;i<=mxn;i++)pa[i]=i,sz[i]=1;}
    int find(int u){
        if(pa[u]==u)return u;
        return pa[u]=find(pa[u]);
    }
    void merg(int u,int v){
        int a=find(u),b=find(v);
        if(a==b)return;
        if(sz[a]>=sz[b]){
            pa[b]=a;
            sz[a]+=sz[b];
            return;
        }
        pa[a]=b;
        sz[b]+=sz[a];
    }
};
/*
void build(vector<vector<int>>v){
    for(auto i:v){
        for(auto j:i)cout<<j<<" ";
        cout<<'\n';
    }
}
*/
vector<int>v[mxn+10];
int construct(vector<vector<int>>p){
    int n=p.size();
    dsu one,two;
    vector<vector<int>>ans(n,vector<int>(n));
    one.init();
    two.init();
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            if(p[i][j]==1)one.merg(i,j);
            if(p[i][j]!=p[j][i])return 0;
        }
    }
    for(int i=0;i<n;i++)v[one.pa[i]].pb(i),one.pa[i]=one.find(i);
    //case one
    for(int i=0;i<n;i++)if(one.pa[i]!=i)ans[i][one.pa[i]]=1,ans[one.pa[i]][i]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            if(p[i][j]==2)two.merg(one.pa[i],one.pa[j]);//grouping
        }
    }
    for(int i=0;i<n;i++)two.pa[i]=two.find(i);
    fill(last,last+mxn,-1);
    fill(first,first+mxn,-1);
    //cyclic connection in group
    for(int i=0;i<n;i++){
        if(v[i].size())continue;
        vector<int>check(n,-1);
        for(int j=0;j<n;j++)check[j]=p[i][j];
        for(int j=1;j<v[i].size();j++){
            for(int k=0;k<n;k++)if(check[j]!=p[v[i][j]][k])return 0;
        }
    }
    for(int i=0;i<n;i++){
        if(one.pa[i]!=i)continue;
        if(last[two.pa[i]]==-1)last[two.pa[i]]=i,first[two.pa[i]]=i;
        else{
            ans[last[two.pa[i]]][i]=1;
            ans[i][last[two.pa[i]]]=1;
            last[two.pa[i]]=i;
        }
    }
    //finish the last connect
    for(int i=0;i<n;i++){
        if(last[i]==-1)continue;
        if(first[i]==last[i])continue;
        if(ans[first[i]][last[i]]){//already connected
            if(v[first[i]].size()>1||v[last[i]].size()>1){
                //connect to second node
                if(v[last[i]].size()>1)swap(first[i],last[i]);
                ans[first[i]][v[last[i]][1]]=1;
                ans[v[last[i]][1]][first[i]]=1;
            }
            else return 0;
            continue;
        }
        ans[first[i]][last[i]]=1;
        ans[last[i]][first[i]]=1;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(p[i][j]!=0)continue;
            if((two.pa[i]==two.pa[j])||(one.pa[i]==one.pa[j]))return 0;
        }
    }
    build(ans);
  return 1;
}
/*
int32_t main(){
    fastio
    int n;cin>>n;
    vector<vector<int>>in(n,vector<int>(n));
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>in[i][j];
    construct(in);
    return 0;
}*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:91:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         for(int j=1;j<v[i].size();j++){
      |                     ~^~~~~~~~~~~~
supertrees.cpp: In function 'void setIO(std::string)':
supertrees.cpp:31:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:32:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 1488 KB Output is correct
7 Correct 169 ms 23380 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 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 1488 KB Output is correct
7 Correct 169 ms 23380 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 744 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1368 KB Output is correct
13 Correct 149 ms 23376 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 80 ms 13632 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 41 ms 6480 KB Output is correct
21 Correct 163 ms 23704 KB Output is correct
22 Correct 149 ms 23380 KB Output is correct
23 Correct 156 ms 23804 KB Output is correct
24 Correct 154 ms 23380 KB Output is correct
25 Correct 70 ms 13648 KB Output is correct
26 Correct 71 ms 13648 KB Output is correct
27 Correct 152 ms 23512 KB Output is correct
28 Correct 150 ms 23348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 488 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 7 ms 1368 KB Output is correct
9 Correct 157 ms 23340 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 6 ms 1372 KB Output is correct
13 Correct 148 ms 23376 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 73 ms 13588 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 38 ms 6480 KB Output is correct
22 Correct 148 ms 23376 KB Output is correct
23 Correct 148 ms 23488 KB Output is correct
24 Correct 156 ms 23468 KB Output is correct
25 Correct 67 ms 13608 KB Output is correct
26 Correct 69 ms 13628 KB Output is correct
27 Correct 152 ms 23376 KB Output is correct
28 Correct 155 ms 23340 KB Output is correct
29 Correct 66 ms 13488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 41 ms 6480 KB Output is correct
5 Correct 152 ms 23336 KB Output is correct
6 Correct 165 ms 23356 KB Output is correct
7 Correct 155 ms 23660 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 38 ms 6448 KB Output is correct
10 Correct 146 ms 23524 KB Output is correct
11 Correct 153 ms 23376 KB Output is correct
12 Correct 157 ms 23580 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 37 ms 6392 KB Output is correct
17 Correct 157 ms 23412 KB Output is correct
18 Correct 152 ms 23376 KB Output is correct
19 Correct 151 ms 23352 KB Output is correct
20 Correct 150 ms 23352 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 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 1488 KB Output is correct
7 Correct 169 ms 23380 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 744 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1368 KB Output is correct
13 Correct 149 ms 23376 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 80 ms 13632 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 41 ms 6480 KB Output is correct
21 Correct 163 ms 23704 KB Output is correct
22 Correct 149 ms 23380 KB Output is correct
23 Correct 156 ms 23804 KB Output is correct
24 Correct 154 ms 23380 KB Output is correct
25 Correct 70 ms 13648 KB Output is correct
26 Correct 71 ms 13648 KB Output is correct
27 Correct 152 ms 23512 KB Output is correct
28 Correct 150 ms 23348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 600 KB Output is correct
33 Correct 0 ms 488 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 1368 KB Output is correct
37 Correct 157 ms 23340 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 6 ms 1372 KB Output is correct
41 Correct 148 ms 23376 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 73 ms 13588 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 38 ms 6480 KB Output is correct
50 Correct 148 ms 23376 KB Output is correct
51 Correct 148 ms 23488 KB Output is correct
52 Correct 156 ms 23468 KB Output is correct
53 Correct 67 ms 13608 KB Output is correct
54 Correct 69 ms 13628 KB Output is correct
55 Correct 152 ms 23376 KB Output is correct
56 Correct 155 ms 23340 KB Output is correct
57 Correct 66 ms 13488 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 3 ms 856 KB Output is correct
61 Correct 80 ms 13632 KB Output is correct
62 Correct 0 ms 600 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 39 ms 6416 KB Output is correct
66 Correct 81 ms 13496 KB Output is correct
67 Correct 71 ms 13632 KB Output is correct
68 Correct 74 ms 13612 KB Output is correct
69 Correct 67 ms 13612 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 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 1488 KB Output is correct
7 Correct 169 ms 23380 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 744 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1368 KB Output is correct
13 Correct 149 ms 23376 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 80 ms 13632 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 41 ms 6480 KB Output is correct
21 Correct 163 ms 23704 KB Output is correct
22 Correct 149 ms 23380 KB Output is correct
23 Correct 156 ms 23804 KB Output is correct
24 Correct 154 ms 23380 KB Output is correct
25 Correct 70 ms 13648 KB Output is correct
26 Correct 71 ms 13648 KB Output is correct
27 Correct 152 ms 23512 KB Output is correct
28 Correct 150 ms 23348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 600 KB Output is correct
33 Correct 0 ms 488 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 1368 KB Output is correct
37 Correct 157 ms 23340 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 6 ms 1372 KB Output is correct
41 Correct 148 ms 23376 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 73 ms 13588 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 38 ms 6480 KB Output is correct
50 Correct 148 ms 23376 KB Output is correct
51 Correct 148 ms 23488 KB Output is correct
52 Correct 156 ms 23468 KB Output is correct
53 Correct 67 ms 13608 KB Output is correct
54 Correct 69 ms 13628 KB Output is correct
55 Correct 152 ms 23376 KB Output is correct
56 Correct 155 ms 23340 KB Output is correct
57 Correct 66 ms 13488 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 41 ms 6480 KB Output is correct
62 Correct 152 ms 23336 KB Output is correct
63 Correct 165 ms 23356 KB Output is correct
64 Correct 155 ms 23660 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 38 ms 6448 KB Output is correct
67 Correct 146 ms 23524 KB Output is correct
68 Correct 153 ms 23376 KB Output is correct
69 Correct 157 ms 23580 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 37 ms 6392 KB Output is correct
74 Correct 157 ms 23412 KB Output is correct
75 Correct 152 ms 23376 KB Output is correct
76 Correct 151 ms 23352 KB Output is correct
77 Correct 150 ms 23352 KB Output is correct
78 Correct 1 ms 344 KB Output is correct
79 Correct 0 ms 344 KB Output is correct
80 Correct 3 ms 856 KB Output is correct
81 Correct 80 ms 13632 KB Output is correct
82 Correct 0 ms 600 KB Output is correct
83 Correct 0 ms 344 KB Output is correct
84 Correct 0 ms 344 KB Output is correct
85 Correct 39 ms 6416 KB Output is correct
86 Correct 81 ms 13496 KB Output is correct
87 Correct 71 ms 13632 KB Output is correct
88 Correct 74 ms 13612 KB Output is correct
89 Correct 67 ms 13612 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 3 ms 856 KB Output is correct
93 Correct 69 ms 13628 KB Output is correct
94 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -