답안 #302191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
302191 2020-09-18T14:07:02 Z aymane7 슈퍼트리 잇기 (IOI20_supertrees) C++17
40 / 100
285 ms 22392 KB
#include<bits/stdc++.h>
#include"supertrees.h"
#pragma GCC optimize("O2")
#define S second
#define F first
#define PB push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(),x.end()
#define L(x) 2*x
#define R(x) 2*x+1
#define M(x,y) (x+y)/2
using namespace std;
typedef long long ll;
const int N=1e3+1;
int p[N],lvl[N];
int getp(int x){
    return (p[x]==x)? x : p[x]=getp(p[x]);
}
void unite(int i,int j){
    int x=getp(i),y=getp(j);
    if(x==y)
        return ;
    if(lvl[x]>lvl[y])
        swap(x,y);
    p[x]=y;
    if(lvl[x]==lvl[y])
        lvl[y]++;
}
/*
void build(vector<vector<int>> t){
    for(auto v:t){
        for(auto x:v)
            cout<<x<<" ";
        cout<<endl;
    }
}
*/
int construct(vector<vector<int>> b){
    int n=sz(b);
    vector<vector<int>> ans(n,vector<int>(n,0));
    for(int i=0;i<n;i++){
        lvl[i]=0;
        p[i]=i;
    }
    int type=1;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            if(b[i][j] && i!=j)
                unite(i,j);
            if(b[i][j]==2)
                type=2;
        }

    vector<int> co[n];
    for(int i=0;i<n;i++)
        co[getp(i)].PB(i);

    for(int i=0;i<n;i++){
        if(sz(co[i])<=1)
            continue;
        if(sz(co[i])==2 && type==2){
            if(b[co[i][0]][co[i][1]]==2)
                return 0;
        }
        for(int j=0;j<sz(co[i])-1;j++)
            ans[co[i][j]][co[i][j+1]]=1,ans[co[i][j+1]][co[i][j]]=1;
        if(type==2)
            ans[co[i][0]][co[i].back()]=1,ans[co[i].back()][co[i][0]]=1;
        for(auto x:co[i])
        for(auto y:co[i]){
            if(x==y)
                continue;
            if(b[x][y]==0)
                return 0;
        }
    }
    build(ans);
    return 1;
}
/*
int main(){
    int n;
    cin>>n;
    vector<vector<int>> t(n,vector<int>(n,0));
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>t[i][j];
    construct(t);
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 12 ms 1280 KB Output is correct
7 Correct 255 ms 22264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 12 ms 1280 KB Output is correct
7 Correct 255 ms 22264 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 234 ms 22136 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 118 ms 12280 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 59 ms 5880 KB Output is correct
21 Correct 235 ms 22084 KB Output is correct
22 Correct 233 ms 22264 KB Output is correct
23 Correct 285 ms 22136 KB Output is correct
24 Correct 241 ms 22108 KB Output is correct
25 Correct 104 ms 12280 KB Output is correct
26 Correct 97 ms 12252 KB Output is correct
27 Correct 260 ms 22136 KB Output is correct
28 Correct 234 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 10 ms 1280 KB Output is correct
9 Correct 232 ms 22104 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 258 ms 22136 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 118 ms 12152 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 60 ms 5844 KB Output is correct
22 Correct 242 ms 22392 KB Output is correct
23 Correct 238 ms 22136 KB Output is correct
24 Correct 257 ms 22264 KB Output is correct
25 Correct 102 ms 12152 KB Output is correct
26 Correct 107 ms 12152 KB Output is correct
27 Correct 237 ms 22264 KB Output is correct
28 Correct 275 ms 22136 KB Output is correct
29 Correct 108 ms 12284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 60 ms 5880 KB Output is correct
5 Correct 260 ms 22264 KB Output is correct
6 Correct 256 ms 22152 KB Output is correct
7 Correct 282 ms 22136 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 61 ms 5880 KB Output is correct
10 Correct 242 ms 22136 KB Output is correct
11 Correct 236 ms 22136 KB Output is correct
12 Correct 271 ms 22104 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Incorrect 0 ms 384 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 12 ms 1280 KB Output is correct
7 Correct 255 ms 22264 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 234 ms 22136 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 118 ms 12280 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 59 ms 5880 KB Output is correct
21 Correct 235 ms 22084 KB Output is correct
22 Correct 233 ms 22264 KB Output is correct
23 Correct 285 ms 22136 KB Output is correct
24 Correct 241 ms 22108 KB Output is correct
25 Correct 104 ms 12280 KB Output is correct
26 Correct 97 ms 12252 KB Output is correct
27 Correct 260 ms 22136 KB Output is correct
28 Correct 234 ms 22100 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 232 ms 22104 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 11 ms 1152 KB Output is correct
41 Correct 258 ms 22136 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 118 ms 12152 KB Output is correct
46 Correct 0 ms 256 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 60 ms 5844 KB Output is correct
50 Correct 242 ms 22392 KB Output is correct
51 Correct 238 ms 22136 KB Output is correct
52 Correct 257 ms 22264 KB Output is correct
53 Correct 102 ms 12152 KB Output is correct
54 Correct 107 ms 12152 KB Output is correct
55 Correct 237 ms 22264 KB Output is correct
56 Correct 275 ms 22136 KB Output is correct
57 Correct 108 ms 12284 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 6 ms 768 KB Output is correct
61 Correct 126 ms 12252 KB Output is correct
62 Correct 0 ms 256 KB Output is correct
63 Incorrect 1 ms 256 KB Too many ways to get from 0 to 9, should be 1 found no less than 2
64 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 12 ms 1280 KB Output is correct
7 Correct 255 ms 22264 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 234 ms 22136 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 118 ms 12280 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 59 ms 5880 KB Output is correct
21 Correct 235 ms 22084 KB Output is correct
22 Correct 233 ms 22264 KB Output is correct
23 Correct 285 ms 22136 KB Output is correct
24 Correct 241 ms 22108 KB Output is correct
25 Correct 104 ms 12280 KB Output is correct
26 Correct 97 ms 12252 KB Output is correct
27 Correct 260 ms 22136 KB Output is correct
28 Correct 234 ms 22100 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 232 ms 22104 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 11 ms 1152 KB Output is correct
41 Correct 258 ms 22136 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 118 ms 12152 KB Output is correct
46 Correct 0 ms 256 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 60 ms 5844 KB Output is correct
50 Correct 242 ms 22392 KB Output is correct
51 Correct 238 ms 22136 KB Output is correct
52 Correct 257 ms 22264 KB Output is correct
53 Correct 102 ms 12152 KB Output is correct
54 Correct 107 ms 12152 KB Output is correct
55 Correct 237 ms 22264 KB Output is correct
56 Correct 275 ms 22136 KB Output is correct
57 Correct 108 ms 12284 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 1 ms 256 KB Output is correct
61 Correct 60 ms 5880 KB Output is correct
62 Correct 260 ms 22264 KB Output is correct
63 Correct 256 ms 22152 KB Output is correct
64 Correct 282 ms 22136 KB Output is correct
65 Correct 0 ms 256 KB Output is correct
66 Correct 61 ms 5880 KB Output is correct
67 Correct 242 ms 22136 KB Output is correct
68 Correct 236 ms 22136 KB Output is correct
69 Correct 271 ms 22104 KB Output is correct
70 Correct 1 ms 256 KB Output is correct
71 Incorrect 0 ms 384 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
72 Halted 0 ms 0 KB -