QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106048#6103. A+B ProblemCrysflyWA 16ms98856kbC++171.7kb2023-05-16 11:21:492023-05-16 11:21: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-16 11:21:52]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:98856kb
  • [2023-05-16 11:21:49]
  • 提交

answer

// what is matter? never mind.
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 2000005
#define inf 0x3f3f3f3f

int n;
vi bag[maxn];

int cnt,fa[maxn];
int newn(vi ch,vi o){
	int u=++cnt;
	bag[u]=o;
	for(int v:ch)fa[v]=u;
	return u;
}

// bag = u,l,r
vi e[maxn];
int dfs(int u)
{
	vi ch;
	for(int v:e[u]) ch.pb(dfs(v));
	if(!ch.size())return newn({},{u,u,u});
	for(int&v:ch) v=newn({v},{bag[v][0],bag[v][1],bag[v][2],u});
	if(ch.size()==1){
		int t=ch[0];
		return newn({t},{u,bag[t][1],bag[t][2]});
	}
	int res=newn({ch[0]},{bag[ch[0]][1],bag[ch[0]][2],bag[ch[1]][1],u});
	res=newn({res,ch[1]},{bag[res][0],bag[ch[1]][1],bag[ch[1]][2],u});
	For(i,2,(int)ch.size()-1){
		int t=ch[i];
		res=newn({res},{bag[res][0],bag[res][2],bag[t][1],u});
		res=newn({res,t},{bag[res][0],bag[t][1],bag[t][2],u});
	}
	return newn({res},{u,bag[res][0],bag[res][2]});
}

signed main()
{
	n=read();
	For(i,2,n){
		int p=read();
		e[p].pb(i);
	}
	int rt=dfs(1);
	cout<<cnt<<"\n";
	For(i,1,cnt){
		sort(bag[i].begin(),bag[i].end());
		bag[i].erase(unique(bag[i].begin(),bag[i].end()),bag[i].end());
		for(int x:bag[i])cout<<x<<" ";
		cout<<"\n";
	}
	For(i,1,cnt)if(fa[i])cout<<fa[i]<<" "<<i<<"\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 16ms
memory: 98856kb

input:

4
1
1
1

output:

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

result:

wrong answer set X[9] is not unique