답안 #374925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
374925 2021-03-08T14:35:18 Z iliccmarko 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
277 ms 24172 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 10000000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
const int N = 1005;
int parent[N], s[N];
 
int find_parent(int u)
{
    while(parent[u]!=u)
    {
        parent[u] = parent[parent[u]];
        u = parent[u];
    }
    return u;
}
 
void dsu(int u, int v)
{
    u = find_parent(u);
    v = find_parent(v);
    if(u!=v)
    {
        if(s[u]<s[v]) swap(u, v);
        s[u] += s[v];
        parent[v] = u;
    }
}
 
 
int construct(vector<vector<int> > p)
{
    int n = len(p);
    for(int i = 0;i<n;i++) parent[i] = i, s[i] = 1;
    for(int i = 0;i<n;i++)
        for(int j = 0;j<n;j++) if(p[i][j]==3) return 0;
    for(int i = 0;i<n;i++)
        for(int j = 0;j<n;j++) if(p[i][j]==1) dsu(i, j);
    vector<int> r;
    vector<int> rr(n, 0);
    vector<vector<int> > res(n, vector<int>(n, 0));
    for(int i = 0;i<n;++i) {
        int x = find_parent(i);
        if(x==i) r.pb(i), rr[i] = 1;
        else res[i][x] = res[x][i] = 1;
    }
    for(int i = 0;i<n;i++)
        for(int j = 0;j<n;j++)
        if(p[i][j]!=p[find_parent(i)][find_parent(j)]) return 0;
    for(int i = 0;i<n;i++)
    {
        if(find_parent(i)==i&&rr[i])
        {
           vector<int> q;
           for(int j = 0;j<n;j++) if(find_parent(j)==i) q.pb(j);
           for(int x : q)
           {
               for(int y : q)
               {
                   if(x!=y)
                   {
                       if(p[x][y]!=1) return 0;
                   }
               }
           }
        }
    }
    for(int i = 0;i<n;i++) parent[i] = i, s[i] = 1;
    for(int i = 0;i<n;++i)
        for(int j = 0;j<n;j++)
        if(rr[i]==1&&rr[j]==1&&p[i][j]==2) dsu(i, j);
    for(int i = 0;i<n;i++)
    {
        if(find_parent(i)==i&&rr[i])
        {
            vector<int> q;
            for(int j = 0;j<n;j++)
                if(find_parent(j)==i) q.pb(j);
            for(int x : q)
            {
                for(int y : q)
                {
                    if(x==y) continue;
                    if(p[x][y]!=2) return 0;
                }
            }
        }
    }
    for(int i = 0;i<n;++i){
        int x = find_parent(i);
        if(x==i&&rr[i])
        {
            if(s[i]==1) continue;
            vector<int> q;
            for(int j = 0;j<n;j++)
                if(rr[j]&&find_parent(j)==i&&j!=i) q.pb(j);
            q.pb(i);
            int pret = i;
            if(len(q)==2) return 0;
            for(int w : q) res[w][pret] = res[pret][w] = 1, pret = w;
        }
    }
    build(res);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 261 ms 22124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 261 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 236 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 273 ms 22124 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 6 ms 748 KB Output is correct
17 Correct 118 ms 12140 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 68 ms 5868 KB Output is correct
21 Correct 267 ms 22124 KB Output is correct
22 Correct 277 ms 22124 KB Output is correct
23 Correct 266 ms 22124 KB Output is correct
24 Correct 257 ms 22124 KB Output is correct
25 Correct 106 ms 12140 KB Output is correct
26 Correct 104 ms 12140 KB Output is correct
27 Correct 268 ms 22252 KB Output is correct
28 Correct 261 ms 22124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 11 ms 1260 KB Output is correct
9 Correct 266 ms 22124 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 265 ms 22252 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 126 ms 14188 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 68 ms 6348 KB Output is correct
22 Correct 264 ms 24044 KB Output is correct
23 Correct 258 ms 24172 KB Output is correct
24 Correct 269 ms 24044 KB Output is correct
25 Correct 116 ms 14188 KB Output is correct
26 Correct 129 ms 14188 KB Output is correct
27 Correct 262 ms 24044 KB Output is correct
28 Correct 277 ms 24172 KB Output is correct
29 Correct 116 ms 14188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 66 ms 5868 KB Output is correct
5 Correct 257 ms 22124 KB Output is correct
6 Correct 261 ms 22116 KB Output is correct
7 Correct 270 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 66 ms 5868 KB Output is correct
10 Correct 256 ms 22252 KB Output is correct
11 Correct 255 ms 22124 KB Output is correct
12 Correct 265 ms 22124 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 66 ms 5868 KB Output is correct
17 Correct 260 ms 22252 KB Output is correct
18 Correct 264 ms 22252 KB Output is correct
19 Correct 264 ms 22124 KB Output is correct
20 Correct 260 ms 22248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 261 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 236 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 273 ms 22124 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 6 ms 748 KB Output is correct
17 Correct 118 ms 12140 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 68 ms 5868 KB Output is correct
21 Correct 267 ms 22124 KB Output is correct
22 Correct 277 ms 22124 KB Output is correct
23 Correct 266 ms 22124 KB Output is correct
24 Correct 257 ms 22124 KB Output is correct
25 Correct 106 ms 12140 KB Output is correct
26 Correct 104 ms 12140 KB Output is correct
27 Correct 268 ms 22252 KB Output is correct
28 Correct 261 ms 22124 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct
33 Correct 0 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 11 ms 1260 KB Output is correct
37 Correct 266 ms 22124 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1260 KB Output is correct
41 Correct 265 ms 22252 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 876 KB Output is correct
45 Correct 126 ms 14188 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 68 ms 6348 KB Output is correct
50 Correct 264 ms 24044 KB Output is correct
51 Correct 258 ms 24172 KB Output is correct
52 Correct 269 ms 24044 KB Output is correct
53 Correct 116 ms 14188 KB Output is correct
54 Correct 129 ms 14188 KB Output is correct
55 Correct 262 ms 24044 KB Output is correct
56 Correct 277 ms 24172 KB Output is correct
57 Correct 116 ms 14188 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 5 ms 876 KB Output is correct
61 Correct 115 ms 14188 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 68 ms 6380 KB Output is correct
66 Correct 116 ms 14188 KB Output is correct
67 Correct 108 ms 14188 KB Output is correct
68 Correct 104 ms 14188 KB Output is correct
69 Correct 115 ms 14188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 261 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 236 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 273 ms 22124 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 6 ms 748 KB Output is correct
17 Correct 118 ms 12140 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 68 ms 5868 KB Output is correct
21 Correct 267 ms 22124 KB Output is correct
22 Correct 277 ms 22124 KB Output is correct
23 Correct 266 ms 22124 KB Output is correct
24 Correct 257 ms 22124 KB Output is correct
25 Correct 106 ms 12140 KB Output is correct
26 Correct 104 ms 12140 KB Output is correct
27 Correct 268 ms 22252 KB Output is correct
28 Correct 261 ms 22124 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct
33 Correct 0 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 11 ms 1260 KB Output is correct
37 Correct 266 ms 22124 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1260 KB Output is correct
41 Correct 265 ms 22252 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 876 KB Output is correct
45 Correct 126 ms 14188 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 68 ms 6348 KB Output is correct
50 Correct 264 ms 24044 KB Output is correct
51 Correct 258 ms 24172 KB Output is correct
52 Correct 269 ms 24044 KB Output is correct
53 Correct 116 ms 14188 KB Output is correct
54 Correct 129 ms 14188 KB Output is correct
55 Correct 262 ms 24044 KB Output is correct
56 Correct 277 ms 24172 KB Output is correct
57 Correct 116 ms 14188 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 66 ms 5868 KB Output is correct
62 Correct 257 ms 22124 KB Output is correct
63 Correct 261 ms 22116 KB Output is correct
64 Correct 270 ms 22124 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 66 ms 5868 KB Output is correct
67 Correct 256 ms 22252 KB Output is correct
68 Correct 255 ms 22124 KB Output is correct
69 Correct 265 ms 22124 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 66 ms 5868 KB Output is correct
74 Correct 260 ms 22252 KB Output is correct
75 Correct 264 ms 22252 KB Output is correct
76 Correct 264 ms 22124 KB Output is correct
77 Correct 260 ms 22248 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 5 ms 876 KB Output is correct
81 Correct 115 ms 14188 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 68 ms 6380 KB Output is correct
86 Correct 116 ms 14188 KB Output is correct
87 Correct 108 ms 14188 KB Output is correct
88 Correct 104 ms 14188 KB Output is correct
89 Correct 115 ms 14188 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 5 ms 748 KB Output is correct
93 Correct 105 ms 10220 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 27 ms 2796 KB Output is correct
98 Correct 102 ms 10220 KB Output is correct
99 Correct 101 ms 10220 KB Output is correct
100 Correct 101 ms 10240 KB Output is correct
101 Correct 100 ms 10220 KB Output is correct
102 Correct 104 ms 10196 KB Output is correct
103 Correct 102 ms 10220 KB Output is correct
104 Correct 104 ms 10220 KB Output is correct
105 Correct 110 ms 10220 KB Output is correct