Submission #336814

# Submission time Handle Problem Language Result Execution time Memory
336814 2020-12-16T22:06:45 Z MvC Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
293 ms 24200 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define lun(x) (int)x.size()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<60);
const int inf=(1<<30);
const int nmax=1e3+50;
const ll mod=1e9+7;
using namespace std;
int n,i,j,t,p1[nmax],p2[nmax];
vector<vector<int> >b;
vector<int>v1[nmax],v2[nmax],vc;
int fnd1(int x)
{
    if(p1[x]==x)return x;
    return p1[x]=fnd1(p1[x]);
}
void uni1(int x,int y)
{
    x=fnd1(x),y=fnd1(y);
    if(x==y)return;
    p1[x]=y;
}
int fnd2(int x)
{
    if(p2[x]==x)return x;
    return p2[x]=fnd2(p2[x]);
}
void uni2(int x,int y)
{
    x=fnd2(x),y=fnd2(y);
    if(x==y)return;
    p2[x]=y;
}
int construct(vector<vector<int> > r)
{
    n=lun(r);
    for(i=0;i<n;i++)for(j=0;j<n;j++)if(r[i][j]==3)return 0;
    for(i=0;i<n;i++)p1[i]=p2[i]=i;
    for(i=0;i<n;i++)for(j=0;j<n;j++)if(r[i][j])uni1(i,j);
    for(i=0;i<n;i++)for(j=0;j<n;j++)if(!r[i][j] && fnd1(i)==fnd1(j))return 0;
    for(i=0;i<n;i++)for(j=0;j<n;j++)if(r[i][j]==1)uni2(i,j);
    for(i=0;i<n;i++)for(j=0;j<n;j++)if(r[i][j]!=1 && fnd2(i)==fnd2(j))return 0;
    for(i=0;i<n;i++)v1[fnd1(i)].pb(i);
    b.resize(n);
    for(i=0;i<n;i++)b[i].resize(n);
    for(i=0;i<n;i++)
    {
        if(v1[i].empty())continue;
        for(j=0;j<lun(v1[i]);j++)v2[fnd2(v1[i][j])].pb(v1[i][j]);
        vc.clear();
        for(j=0;j<n;j++)
        {
            if(v2[j].empty())continue;
            for(t=0;t<lun(v2[j])-1;t++)
            {
                b[v2[j][t]][v2[j][t+1]]=b[v2[j][t+1]][v2[j][t]]=1;
            }
            vc.pb(j);
            v2[j].clear();
        }
        if(lun(vc)==2)return 0;
        for(j=0;j<lun(vc)-1;j++)b[vc[j]][vc[j+1]]=b[vc[j+1]][vc[j]]=1;
        if(lun(vc)!=1)b[vc[0]][vc.back()]=b[vc.back()][vc[0]]=1;
    }
    build(b);
    return 1;
}
/*int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);

    return 0;
}*/
# Verdict Execution time Memory 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 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 262 ms 22252 KB Output is correct
# Verdict Execution time Memory 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 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 262 ms 22252 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 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 1280 KB Output is correct
13 Correct 257 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 5 ms 748 KB Output is correct
17 Correct 111 ms 8300 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 69 ms 5868 KB Output is correct
21 Correct 272 ms 22252 KB Output is correct
22 Correct 271 ms 22124 KB Output is correct
23 Correct 293 ms 22252 KB Output is correct
24 Correct 257 ms 22252 KB Output is correct
25 Correct 101 ms 8300 KB Output is correct
26 Correct 101 ms 8300 KB Output is correct
27 Correct 289 ms 22252 KB Output is correct
28 Correct 258 ms 22400 KB Output is correct
# Verdict Execution time Memory 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 1 ms 364 KB Output is correct
5 Correct 1 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 1388 KB Output is correct
9 Correct 259 ms 24172 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1388 KB Output is correct
13 Correct 250 ms 24200 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 110 ms 10220 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 67 ms 6380 KB Output is correct
22 Correct 265 ms 24172 KB Output is correct
23 Correct 265 ms 24172 KB Output is correct
24 Correct 281 ms 24172 KB Output is correct
25 Correct 117 ms 14316 KB Output is correct
26 Correct 102 ms 10220 KB Output is correct
27 Correct 261 ms 24172 KB Output is correct
28 Correct 273 ms 24172 KB Output is correct
29 Correct 116 ms 14444 KB Output is correct
# Verdict Execution time Memory 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 70 ms 6380 KB Output is correct
5 Correct 273 ms 24172 KB Output is correct
6 Correct 268 ms 24172 KB Output is correct
7 Correct 292 ms 24172 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 66 ms 6380 KB Output is correct
10 Correct 266 ms 24200 KB Output is correct
11 Correct 266 ms 24172 KB Output is correct
12 Correct 281 ms 24172 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 68 ms 6380 KB Output is correct
17 Correct 267 ms 24200 KB Output is correct
18 Correct 271 ms 24172 KB Output is correct
19 Correct 273 ms 24172 KB Output is correct
20 Correct 261 ms 24172 KB Output is correct
# Verdict Execution time Memory 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 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 262 ms 22252 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 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 1280 KB Output is correct
13 Correct 257 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 5 ms 748 KB Output is correct
17 Correct 111 ms 8300 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 69 ms 5868 KB Output is correct
21 Correct 272 ms 22252 KB Output is correct
22 Correct 271 ms 22124 KB Output is correct
23 Correct 293 ms 22252 KB Output is correct
24 Correct 257 ms 22252 KB Output is correct
25 Correct 101 ms 8300 KB Output is correct
26 Correct 101 ms 8300 KB Output is correct
27 Correct 289 ms 22252 KB Output is correct
28 Correct 258 ms 22400 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 1 ms 364 KB Output is correct
33 Correct 1 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 1388 KB Output is correct
37 Correct 259 ms 24172 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1388 KB Output is correct
41 Correct 250 ms 24200 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 5 ms 748 KB Output is correct
45 Correct 110 ms 10220 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 67 ms 6380 KB Output is correct
50 Correct 265 ms 24172 KB Output is correct
51 Correct 265 ms 24172 KB Output is correct
52 Correct 281 ms 24172 KB Output is correct
53 Correct 117 ms 14316 KB Output is correct
54 Correct 102 ms 10220 KB Output is correct
55 Correct 261 ms 24172 KB Output is correct
56 Correct 273 ms 24172 KB Output is correct
57 Correct 116 ms 14444 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 748 KB Output is correct
61 Correct 108 ms 10220 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 67 ms 6380 KB Output is correct
66 Correct 112 ms 10220 KB Output is correct
67 Correct 108 ms 10348 KB Output is correct
68 Correct 101 ms 10220 KB Output is correct
69 Correct 114 ms 14188 KB Output is correct
# Verdict Execution time Memory 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 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 262 ms 22252 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 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 1280 KB Output is correct
13 Correct 257 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 5 ms 748 KB Output is correct
17 Correct 111 ms 8300 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 69 ms 5868 KB Output is correct
21 Correct 272 ms 22252 KB Output is correct
22 Correct 271 ms 22124 KB Output is correct
23 Correct 293 ms 22252 KB Output is correct
24 Correct 257 ms 22252 KB Output is correct
25 Correct 101 ms 8300 KB Output is correct
26 Correct 101 ms 8300 KB Output is correct
27 Correct 289 ms 22252 KB Output is correct
28 Correct 258 ms 22400 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 1 ms 364 KB Output is correct
33 Correct 1 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 1388 KB Output is correct
37 Correct 259 ms 24172 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1388 KB Output is correct
41 Correct 250 ms 24200 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 5 ms 748 KB Output is correct
45 Correct 110 ms 10220 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 67 ms 6380 KB Output is correct
50 Correct 265 ms 24172 KB Output is correct
51 Correct 265 ms 24172 KB Output is correct
52 Correct 281 ms 24172 KB Output is correct
53 Correct 117 ms 14316 KB Output is correct
54 Correct 102 ms 10220 KB Output is correct
55 Correct 261 ms 24172 KB Output is correct
56 Correct 273 ms 24172 KB Output is correct
57 Correct 116 ms 14444 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 70 ms 6380 KB Output is correct
62 Correct 273 ms 24172 KB Output is correct
63 Correct 268 ms 24172 KB Output is correct
64 Correct 292 ms 24172 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 66 ms 6380 KB Output is correct
67 Correct 266 ms 24200 KB Output is correct
68 Correct 266 ms 24172 KB Output is correct
69 Correct 281 ms 24172 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 68 ms 6380 KB Output is correct
74 Correct 267 ms 24200 KB Output is correct
75 Correct 271 ms 24172 KB Output is correct
76 Correct 273 ms 24172 KB Output is correct
77 Correct 261 ms 24172 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 748 KB Output is correct
81 Correct 108 ms 10220 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 67 ms 6380 KB Output is correct
86 Correct 112 ms 10220 KB Output is correct
87 Correct 108 ms 10348 KB Output is correct
88 Correct 101 ms 10220 KB Output is correct
89 Correct 114 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 4 ms 748 KB Output is correct
93 Correct 99 ms 10348 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 25 ms 2796 KB Output is correct
98 Correct 101 ms 10220 KB Output is correct
99 Correct 99 ms 10220 KB Output is correct
100 Correct 99 ms 10348 KB Output is correct
101 Correct 102 ms 10220 KB Output is correct
102 Correct 87 ms 10220 KB Output is correct
103 Correct 86 ms 10220 KB Output is correct
104 Correct 86 ms 10220 KB Output is correct
105 Correct 99 ms 10232 KB Output is correct