QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107347#6103. A+B Problembulijiojiodibuliduo#RE 238ms55204kbC++1.9kb2023-05-21 01:46:492023-05-21 01:46:52

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-21 01:46:52]
  • 评测
  • 测评结果:RE
  • 用时:238ms
  • 内存:55204kb
  • [2023-05-21 01:46:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=401000;
int p[N],n,t,nxt[N];
VI v[N],son[N];
vector<PII> ans;
int dfs(int u) {
	if (SZ(son[u])==0) {
		v[++t]={u,u,nxt[u]};
		return t;
	} else {
		VI meg;
		for (auto v:son[u]) {
			meg.pb(dfs(v));
		}
		VI pre=v[meg[0]];
		v[++t]={u,pre[0],pre[1],pre[2]};
		ans.pb({t,meg[0]});
		v[++t]={u,pre[1],pre[2]};
		ans.pb({t,t-1});
		int rid=t;
		rep(i,1,SZ(meg)) {
			VI cur=v[meg[i]];
			v[++t]={u,cur[0],cur[1],cur[2]};
			ans.pb({t,meg[i]});
			v[++t]={u,cur[1],cur[2]};
			ans.pb({t,t-1});
			//printf("pre %d %d %d\n",pre[0],pre[1],pre[2]);
			//printf("cur %d %d %d\n",cur[0],cur[1],cur[2]);
			assert(pre[2]==cur[1]);
			v[++t]={u,pre[1],pre[2],cur[2]};
			ans.pb({t,rid});
			ans.pb({t,t-1});
			v[++t]={u,pre[1],cur[2]};
			ans.pb({t,t-1});
			pre=v[t];
			rid=t;
		}
		return rid;
	}
}

int main() {
	scanf("%d",&n);
	rep(i,2,n+1) {
		scanf("%d",&p[i]);
		son[p[i]].pb(i);
	}
	VI lef;
	rep(i,1,n+1) if (son[i].empty()) {
		lef.pb(i);
	}
	rep(i,0,SZ(lef)) nxt[lef[i]]=lef[(i+1)%SZ(lef)];
	dfs(1);
	printf("%d\n",t);
	assert(SZ(ans)==t-1);
	rep(i,1,t+1) {
		set<int> ps(all(v[i]));
		printf("%d ",SZ(ps));
		for (auto x:ps) printf("%d ",x); puts("");
	}
	for (auto [u,v]:ans) printf("%d %d\n",u,v);
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 22464kb

input:

4
1
1
1

output:

13
2 2 3 
2 3 4 
2 2 4 
3 1 2 3 
3 1 2 3 
3 1 3 4 
3 1 3 4 
4 1 2 3 4 
3 1 2 4 
3 1 2 4 
3 1 2 4 
3 1 2 4 
2 1 2 
4 1
5 4
6 2
7 6
8 5
8 7
9 8
10 3
11 10
12 9
12 11
13 12

result:

ok partial = 0

Test #2:

score: 0
Accepted
time: 5ms
memory: 22472kb

input:

11
1
1
3
4
4
3
1
8
8
10

output:

36
2 2 5 
2 5 6 
2 6 7 
3 4 5 6 
3 4 5 6 
3 4 6 7 
3 4 6 7 
4 4 5 6 7 
3 4 5 7 
2 7 9 
4 3 4 5 7 
3 3 5 7 
3 3 7 9 
3 3 7 9 
4 3 5 7 9 
3 3 5 9 
2 9 11 
2 2 11 
3 2 10 11 
3 2 10 11 
3 8 9 11 
3 8 9 11 
4 2 8 10 11 
3 2 8 11 
4 2 8 9 11 
3 2 8 9 
3 1 2 5 
3 1 2 5 
4 1 3 5 9 
3 1 5 9 
4 1 2 5 9 
3 1 ...

result:

ok partial = 0

Test #3:

score: 0
Accepted
time: 150ms
memory: 33948kb

input:

99998
1
1
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
1
94
95
96
97
98
99
100
101...

output:

201342
2 2 93 
2 93 842 
3 92 93 842 
3 92 93 842 
4 91 92 93 842 
3 91 93 842 
4 90 91 93 842 
3 90 93 842 
4 89 90 93 842 
3 89 93 842 
4 88 89 93 842 
3 88 93 842 
4 87 88 93 842 
3 87 93 842 
4 86 87 93 842 
3 86 93 842 
4 85 86 93 842 
3 85 93 842 
4 84 85 93 842 
3 84 93 842 
4 83 84 93 842 
3...

result:

ok partial = 0

Test #4:

score: 0
Accepted
time: 132ms
memory: 55204kb

input:

99998
1
1
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
100
10...

output:

200007
2 2 12098 
2 12098 16424 
3 12097 12098 16424 
3 12097 12098 16424 
4 12096 12097 12098 16424 
3 12096 12098 16424 
4 12095 12096 12098 16424 
3 12095 12098 16424 
4 12094 12095 12098 16424 
3 12094 12098 16424 
4 12093 12094 12098 16424 
3 12093 12098 16424 
4 12092 12093 12098 16424 
3 1209...

result:

ok partial = 0

Test #5:

score: 0
Accepted
time: 238ms
memory: 44524kb

input:

99998
1
2
3
3
5
6
6
8
9
10
11
11
11
14
15
15
17
17
19
20
21
21
23
23
25
25
27
27
29
30
31
32
33
34
35
35
37
38
39
40
40
42
42
44
45
46
47
48
48
50
50
52
53
54
55
55
57
58
58
60
61
62
63
64
65
65
67
68
69
70
70
72
73
74
75
76
76
78
79
80
80
82
82
84
85
85
87
87
89
90
91
91
93
93
93
96
96
98
98
100
10...

output:

377457
2 4 7 
2 7 12 
2 12 13 
2 13 16 
2 16 18 
2 18 22 
2 22 24 
2 24 26 
2 26 28 
2 28 36 
2 36 41 
2 41 43 
2 43 49 
2 49 51 
2 51 56 
2 56 59 
2 59 66 
2 66 71 
2 71 77 
2 77 81 
2 81 83 
2 83 86 
2 86 88 
2 88 92 
2 92 94 
2 94 95 
2 95 97 
2 97 99 
2 99 104 
2 104 105 
2 105 112 
2 112 113 
2...

result:

ok partial = 0

Test #6:

score: 0
Accepted
time: 215ms
memory: 50104kb

input:

99997
1
1
3
4
4
6
6
8
9
9
11
11
13
13
15
15
17
18
19
20
21
22
23
23
25
25
27
28
29
30
31
31
33
33
35
35
37
37
39
40
40
42
42
44
44
46
46
48
48
50
51
51
53
53
55
56
57
57
59
59
61
62
62
64
64
66
66
68
69
69
71
72
73
73
75
76
76
78
78
80
80
82
82
84
84
86
86
88
88
90
91
91
93
93
95
95
97
97
99
99
101
...

output:

350014
2 2 5 
2 5 7 
2 7 10 
2 10 12 
2 12 14 
2 14 16 
2 16 24 
2 24 26 
2 26 32 
2 32 34 
2 34 36 
2 36 38 
2 38 41 
2 41 43 
2 43 45 
2 45 47 
2 47 49 
2 49 52 
2 52 54 
2 54 58 
2 58 60 
2 60 63 
2 63 65 
2 65 67 
2 67 70 
2 70 74 
2 74 77 
2 77 79 
2 79 81 
2 81 83 
2 83 85 
2 85 87 
2 87 89 
2...

result:

ok partial = 0

Test #7:

score: -100
Runtime Error

input:

99998
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:


result: