General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
63533941 Practice:
Zory
1246D - 9 GNU C++14 Accepted 124 ms 27092 KB 2019-10-27 10:31:30 2019-10-27 10:31:30
 
 
→ Source
//Zory-2019
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    int fa[N];vc<pr> son[N];
    int linkfa[N],endpos[N];//链
    vc<int> oper;void output(int x,int times){while(times--)oper.PB(x);}
    vc<int> ans;
    void main()
    {
        int n=qread();fo(i,1,n-1) fa[i]=qread();
        fd(x,n-1,0)
        {
            sort(all(son[x]));//(ln,sonid)
            int ln=1;endpos[x]=x;
            if(sz(son[x]))
            {
                ln+=son[x].back().FR;
                linkfa[son[x][0].SE]=x;
                fo(t,1,sz(son[x])-1) output(son[x][t].SE,son[x][t-1].FR),linkfa[son[x][t].SE]=endpos[son[x][t-1].SE];
                endpos[x]=endpos[son[x].back().SE];
            }
            if(x>0) son[fa[x]].PB(MP(ln,x)); else linkfa[0]=-1;
        }
        for(int x=endpos[0];x>=0;x=linkfa[x]) ans.PB(x);fd(t,sz(ans)-1,0) write1(ans[t]);puts("");
        write2(sz(oper));for(auto t:oper) write1(t);
    }
};//(ans+MOD)%MOD
signed main()
{
    // freopen("a.in","r",stdin);
    srand(time(0));
    mine::main();
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details