답안 #302231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
302231 2020-09-18T14:34:15 Z aymane7 슈퍼트리 잇기 (IOI20_supertrees) C++17
40 / 100
267 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 build1(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));
    vector<int> co[n];
    bool ex2[n]={0};
    for(int i=0;i<n;i++){
        lvl[i]=0;
        p[i]=i;
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            if(b[i][j]==2)
                unite(i,j),ex2[i]=1;
        }


    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){
            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;
        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;
        }
    }


    //b[i][j]=1
    for(int i=0;i<n;i++){
        lvl[i]=0;
        p[i]=i;
        co[i].clear();
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            if(b[i][j]==1)
                unite(i,j);
        }
    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;
        for(int j=0;j<sz(co[i]);j++){
            if(ex2[co[i][j]]){
                swap(co[i][j],co[i][0]);
                break;
            }
        }
        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;
        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 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 253 ms 22104 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 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 253 ms 22104 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 12 ms 1280 KB Output is correct
13 Correct 242 ms 22140 KB Output is correct
14 Correct 0 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 121 ms 12252 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 61 ms 5880 KB Output is correct
21 Correct 243 ms 22136 KB Output is correct
22 Correct 233 ms 22136 KB Output is correct
23 Correct 267 ms 22392 KB Output is correct
24 Correct 228 ms 22136 KB Output is correct
25 Correct 99 ms 12280 KB Output is correct
26 Correct 103 ms 12152 KB Output is correct
27 Correct 258 ms 22136 KB Output is correct
28 Correct 247 ms 22136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 10 ms 1280 KB Output is correct
9 Correct 267 ms 22108 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 11 ms 1280 KB Output is correct
13 Correct 246 ms 22184 KB Output is correct
14 Correct 0 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 117 ms 12152 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 61 ms 5880 KB Output is correct
22 Correct 233 ms 22136 KB Output is correct
23 Correct 240 ms 22136 KB Output is correct
24 Correct 254 ms 22136 KB Output is correct
25 Correct 100 ms 12156 KB Output is correct
26 Correct 113 ms 12152 KB Output is correct
27 Correct 234 ms 22136 KB Output is correct
28 Correct 254 ms 22136 KB Output is correct
29 Correct 93 ms 12280 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 256 KB Output is correct
4 Correct 59 ms 5880 KB Output is correct
5 Correct 248 ms 22236 KB Output is correct
6 Correct 238 ms 22264 KB Output is correct
7 Correct 254 ms 22264 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 59 ms 5880 KB Output is correct
10 Correct 240 ms 22264 KB Output is correct
11 Correct 233 ms 22136 KB Output is correct
12 Correct 259 ms 22136 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Incorrect 0 ms 256 KB Too many ways to get from 0 to 4, should be 1 found no less than 2
16 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 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 253 ms 22104 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 12 ms 1280 KB Output is correct
13 Correct 242 ms 22140 KB Output is correct
14 Correct 0 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 121 ms 12252 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 61 ms 5880 KB Output is correct
21 Correct 243 ms 22136 KB Output is correct
22 Correct 233 ms 22136 KB Output is correct
23 Correct 267 ms 22392 KB Output is correct
24 Correct 228 ms 22136 KB Output is correct
25 Correct 99 ms 12280 KB Output is correct
26 Correct 103 ms 12152 KB Output is correct
27 Correct 258 ms 22136 KB Output is correct
28 Correct 247 ms 22136 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 0 ms 256 KB Output is correct
35 Correct 0 ms 256 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 267 ms 22108 KB Output is correct
38 Correct 0 ms 256 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 11 ms 1280 KB Output is correct
41 Correct 246 ms 22184 KB Output is correct
42 Correct 0 ms 256 KB Output is correct
43 Correct 0 ms 256 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 117 ms 12152 KB Output is correct
46 Correct 0 ms 256 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 1 ms 256 KB Output is correct
49 Correct 61 ms 5880 KB Output is correct
50 Correct 233 ms 22136 KB Output is correct
51 Correct 240 ms 22136 KB Output is correct
52 Correct 254 ms 22136 KB Output is correct
53 Correct 100 ms 12156 KB Output is correct
54 Correct 113 ms 12152 KB Output is correct
55 Correct 234 ms 22136 KB Output is correct
56 Correct 254 ms 22136 KB Output is correct
57 Correct 93 ms 12280 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 7 ms 768 KB Output is correct
61 Correct 113 ms 12280 KB Output is correct
62 Correct 1 ms 256 KB Output is correct
63 Correct 1 ms 256 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Incorrect 62 ms 5880 KB Too many ways to get from 1 to 269, should be 1 found no less than 2
66 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 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 253 ms 22104 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 12 ms 1280 KB Output is correct
13 Correct 242 ms 22140 KB Output is correct
14 Correct 0 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 121 ms 12252 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 61 ms 5880 KB Output is correct
21 Correct 243 ms 22136 KB Output is correct
22 Correct 233 ms 22136 KB Output is correct
23 Correct 267 ms 22392 KB Output is correct
24 Correct 228 ms 22136 KB Output is correct
25 Correct 99 ms 12280 KB Output is correct
26 Correct 103 ms 12152 KB Output is correct
27 Correct 258 ms 22136 KB Output is correct
28 Correct 247 ms 22136 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 0 ms 256 KB Output is correct
35 Correct 0 ms 256 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 267 ms 22108 KB Output is correct
38 Correct 0 ms 256 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 11 ms 1280 KB Output is correct
41 Correct 246 ms 22184 KB Output is correct
42 Correct 0 ms 256 KB Output is correct
43 Correct 0 ms 256 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 117 ms 12152 KB Output is correct
46 Correct 0 ms 256 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 1 ms 256 KB Output is correct
49 Correct 61 ms 5880 KB Output is correct
50 Correct 233 ms 22136 KB Output is correct
51 Correct 240 ms 22136 KB Output is correct
52 Correct 254 ms 22136 KB Output is correct
53 Correct 100 ms 12156 KB Output is correct
54 Correct 113 ms 12152 KB Output is correct
55 Correct 234 ms 22136 KB Output is correct
56 Correct 254 ms 22136 KB Output is correct
57 Correct 93 ms 12280 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 0 ms 256 KB Output is correct
61 Correct 59 ms 5880 KB Output is correct
62 Correct 248 ms 22236 KB Output is correct
63 Correct 238 ms 22264 KB Output is correct
64 Correct 254 ms 22264 KB Output is correct
65 Correct 0 ms 256 KB Output is correct
66 Correct 59 ms 5880 KB Output is correct
67 Correct 240 ms 22264 KB Output is correct
68 Correct 233 ms 22136 KB Output is correct
69 Correct 259 ms 22136 KB Output is correct
70 Correct 0 ms 256 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Incorrect 0 ms 256 KB Too many ways to get from 0 to 4, should be 1 found no less than 2
73 Halted 0 ms 0 KB -