QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560403#9241. Sphinxchenxinyang2006#24 424ms4892kbC++203.2kb2024-09-12 15:35:062024-09-12 15:35:07

Judging History

This is the latest submission verdict.

  • [2024-09-12 15:35:07]
  • Judged
  • Verdict: 24
  • Time: 424ms
  • Memory: 4892kb
  • [2024-09-12 15:35:06]
  • Submitted

answer

#include "sphinx.h"
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
  if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
  if(x > y) x = y;
}

inline int popcnt(int x){
  return __builtin_popcount(x);
}

inline int ctz(int x){
  return __builtin_ctz(x);
}
int n;
vector <int> G[255];
int fa[255],col[255],vis[255],cur[255],ord[255];
int fnd(int u){
    if(fa[u] == u) return u;
    return fa[u] = fnd(fa[u]);
}
void mrg(int u,int v){
    u = fnd(u);v = fnd(v);
    if(u == v) return;
    fa[u] = v;
}

int test(vector <int> &C){
    rep(u,1,n) fa[u] = u;
    rep(u,1,n){
        for(int v:G[u]){
            if(C[u - 1] == C[v - 1]) mrg(u,v);
        }
    }
    int result = 0;
    rep(u,1,n) result += fa[u] == u;
    return result;
}

int query(vector <int> &C){
    assert(SZ(C) == n);
    int ret = perform_experiment(C);
//    for(int c:C) printf("%d ",c);
//    printf("ret=%d\n",ret);
    return ret;
}

bool cmp(int x,int y){
    return cur[x] < cur[y];
}

int check(vector <int> &C){
    int res1 = test(C),res2 = query(C);
//    for(int c:C) printf("%d ",c);
//    printf("\n%d %d\n",res1,res2);
    return res1 == res2;
}
int sz;
pii idx[255];
vector <int> find_colours(int N, vector<int> X,vector<int> Y) {
    n = N;
    rep(i,0,SZ(X) - 1){
        X[i]++;Y[i]++;
        G[X[i]].eb(Y[i]);
        G[Y[i]].eb(X[i]);
    }
    rep(u,1,n) cur[u] = 0;
    vector <int> ans(n),C(n),CC(n);
    while(1){
        rep(u,1,n){
            ord[u] = u;
            vis[u] = 0;
        }
        sort(ord + 1,ord + n + 1,cmp);
        if(cur[ord[1]] >= n) break;

        sz = 0;
        rep(_i,1,n){
            int u = ord[_i];
            if(vis[u]) continue;
            vis[u] = 1;
            col[u] = -1;
            for(int v:G[u]){
                if(vis[v]) continue;
                vis[v] = 1;
                col[v] = cur[u]++;
                idx[++sz] = mkp(u,v);
//                printf("%d:(%d,%d)\n",sz,u,v);
                chkmin(cur[u],n);
            }
        }
//        rep(u,1,n) printf("%d ",col[u]);
//        printf("\n");
        rep(u,1,n){
            if(!vis[u]) col[u] = n;
            C[u - 1] = col[u];
        }
        if(check(C)) continue;

        int pl = 1,pr = sz,mid;
        while(pl != pr){
            mid = (pl + pr) >> 1;
            CC = C;
            rep(i,1,pl - 1) CC[idx[i].second - 1] = n;
            rep(i,mid+1,sz) CC[idx[i].second - 1] = n;
            if(check(CC)) pl = mid + 1;
            else pr = mid;
        }
        ans[idx[pl].first - 1] = col[idx[pl].second];
    }
    return ans;
}
/*
g++ sphinx3.cpp grader.cpp -o grader3.exe -Wall -Wshadow -O2 -std=c++14
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 1ms
memory: 3832kb

input:

1978433568
2
1
0
1
1978433568
1
1978433568
1
1978433568
2
1978433568
2

output:

877694080
-1
0
877694080
0
-1
877694080
-1
1
877694080
1
-1
877694081
0
0

result:

ok #experiments: 4

Test #2:

score: 3
Accepted
time: 1ms
memory: 3792kb

input:

1978433568
2
1
0
1
1978433568
1
1978433568
2
1978433568
2
1978433568
1

output:

877694080
-1
0
877694080
0
-1
877694080
-1
1
877694080
1
-1
877694081
0
1

result:

ok #experiments: 4

Test #3:

score: 3
Accepted
time: 1ms
memory: 4136kb

input:

1978433568
2
1
0
1
1978433568
2
1978433568
1
1978433568
1
1978433568
2

output:

877694080
-1
0
877694080
0
-1
877694080
-1
1
877694080
1
-1
877694081
1
0

result:

ok #experiments: 4

Test #4:

score: 3
Accepted
time: 1ms
memory: 4096kb

input:

1978433568
2
1
0
1
1978433568
2
1978433568
2
1978433568
1
1978433568
1

output:

877694080
-1
0
877694080
0
-1
877694080
-1
1
877694080
1
-1
877694081
1
1

result:

ok #experiments: 4

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #5:

score: 0
Wrong Answer
time: 2ms
memory: 3788kb

input:

1978433568
50
49
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
47
48
48
49
19784335...

output:

877694080
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
877694080
-1
0
-1
0
-1
1
-1
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
-1
1
-1
0
-1
0
0
-1
1
-1
0
-1
0
-1
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
877694080
-1
0
-1
1
-1
0
-1
1
1...

result:

wrong answer Vertices 11 and 12 do have the same color, but they do not in returned answer

Subtask #3:

score: 0
Wrong Answer

Test #34:

score: 0
Wrong Answer
time: 14ms
memory: 3804kb

input:

1978433568
250
249
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
47
48
48
49
49
50
...

output:

877694080
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
1
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
0
-1
1
-1
0
-1
0
-1...

result:

wrong answer Vertices 26 and 27 do have the same color, but they do not in returned answer

Subtask #4:

score: 21
Accepted

Test #43:

score: 21
Accepted
time: 385ms
memory: 4664kb

input:

1978433568
250
31125
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
0
16
0
17
0
18
0
19
0
20
0
21
0
22
0
23
0
24
0
25
0
26
0
27
0
28
0
29
0
30
0
31
0
32
0
33
0
34
0
35
0
36
0
37
0
38
0
39
0
40
0
41
0
42
0
43
0
44
0
45
0
46
0
47
0
48
0
49
0
50
0
51
0
52
0
53
0
54
0
55
0
56
0
57
0
5...

output:

877694080
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...

result:

ok #experiments: 2388

Test #44:

score: 21
Accepted
time: 410ms
memory: 4676kb

input:

1978433568
250
31125
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
0
16
0
17
0
18
0
19
0
20
0
21
0
22
0
23
0
24
0
25
0
26
0
27
0
28
0
29
0
30
0
31
0
32
0
33
0
34
0
35
0
36
0
37
0
38
0
39
0
40
0
41
0
42
0
43
0
44
0
45
0
46
0
47
0
48
0
49
0
50
0
51
0
52
0
53
0
54
0
55
0
56
0
57
0
5...

output:

877694080
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...

result:

ok #experiments: 2500

Test #45:

score: 21
Accepted
time: 419ms
memory: 4612kb

input:

1978433568
250
31125
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
0
16
0
17
0
18
0
19
0
20
0
21
0
22
0
23
0
24
0
25
0
26
0
27
0
28
0
29
0
30
0
31
0
32
0
33
0
34
0
35
0
36
0
37
0
38
0
39
0
40
0
41
0
42
0
43
0
44
0
45
0
46
0
47
0
48
0
49
0
50
0
51
0
52
0
53
0
54
0
55
0
56
0
57
0
5...

output:

877694080
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...

result:

ok #experiments: 2500

Test #46:

score: 21
Accepted
time: 424ms
memory: 4664kb

input:

1978433568
250
31125
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
0
16
0
17
0
18
0
19
0
20
0
21
0
22
0
23
0
24
0
25
0
26
0
27
0
28
0
29
0
30
0
31
0
32
0
33
0
34
0
35
0
36
0
37
0
38
0
39
0
40
0
41
0
42
0
43
0
44
0
45
0
46
0
47
0
48
0
49
0
50
0
51
0
52
0
53
0
54
0
55
0
56
0
57
0
5...

output:

877694080
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...

result:

ok #experiments: 2493

Test #47:

score: 21
Accepted
time: 405ms
memory: 4856kb

input:

1978433568
250
31125
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
0
16
0
17
0
18
0
19
0
20
0
21
0
22
0
23
0
24
0
25
0
26
0
27
0
28
0
29
0
30
0
31
0
32
0
33
0
34
0
35
0
36
0
37
0
38
0
39
0
40
0
41
0
42
0
43
0
44
0
45
0
46
0
47
0
48
0
49
0
50
0
51
0
52
0
53
0
54
0
55
0
56
0
57
0
5...

output:

877694080
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...

result:

ok #experiments: 2492

Test #48:

score: 21
Accepted
time: 410ms
memory: 4552kb

input:

1978433568
250
31125
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
0
16
0
17
0
18
0
19
0
20
0
21
0
22
0
23
0
24
0
25
0
26
0
27
0
28
0
29
0
30
0
31
0
32
0
33
0
34
0
35
0
36
0
37
0
38
0
39
0
40
0
41
0
42
0
43
0
44
0
45
0
46
0
47
0
48
0
49
0
50
0
51
0
52
0
53
0
54
0
55
0
56
0
57
0
5...

output:

877694080
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...

result:

ok #experiments: 2497

Test #49:

score: 21
Accepted
time: 398ms
memory: 4892kb

input:

1978433568
250
31125
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
0
16
0
17
0
18
0
19
0
20
0
21
0
22
0
23
0
24
0
25
0
26
0
27
0
28
0
29
0
30
0
31
0
32
0
33
0
34
0
35
0
36
0
37
0
38
0
39
0
40
0
41
0
42
0
43
0
44
0
45
0
46
0
47
0
48
0
49
0
50
0
51
0
52
0
53
0
54
0
55
0
56
0
57
0
5...

output:

877694080
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...

result:

ok #experiments: 2493

Test #50:

score: 21
Accepted
time: 422ms
memory: 4892kb

input:

1978433568
250
31125
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
0
16
0
17
0
18
0
19
0
20
0
21
0
22
0
23
0
24
0
25
0
26
0
27
0
28
0
29
0
30
0
31
0
32
0
33
0
34
0
35
0
36
0
37
0
38
0
39
0
40
0
41
0
42
0
43
0
44
0
45
0
46
0
47
0
48
0
49
0
50
0
51
0
52
0
53
0
54
0
55
0
56
0
57
0
5...

output:

877694080
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...

result:

ok #experiments: 2500

Test #51:

score: 21
Accepted
time: 417ms
memory: 4892kb

input:

1978433568
250
31125
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
0
16
0
17
0
18
0
19
0
20
0
21
0
22
0
23
0
24
0
25
0
26
0
27
0
28
0
29
0
30
0
31
0
32
0
33
0
34
0
35
0
36
0
37
0
38
0
39
0
40
0
41
0
42
0
43
0
44
0
45
0
46
0
47
0
48
0
49
0
50
0
51
0
52
0
53
0
54
0
55
0
56
0
57
0
5...

output:

877694080
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...

result:

ok #experiments: 2493

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%