QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303213#7769. Axium Crisismyee100 ✓1305ms84560kbC++114.2kb2024-01-11 21:35:342024-01-11 21:35:34

Judging History

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

  • [2024-01-11 21:35:34]
  • 评测
  • 测评结果:100
  • 用时:1305ms
  • 内存:84560kb
  • [2024-01-11 21:35:34]
  • 提交

answer

// 那就是希望。
// 即便需要取模,也是光明。

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
// Your shadow Gets in the way of my light
uint U[18],V[18],W[18];
std::vector<uint>E[18];
uint End[1u<<18|1],S[1u<<20|1],From[1u<<20|1],To[1u<<20|1],Last[1u<<20|1],cnt;
uint Go[18][18];
voi dfs0(uint p,uint r,uint a,uint b)
{
    if(b)Last[cnt]=End[a],S[cnt]=b,From[cnt]=p,To[cnt]=r,End[a]=cnt++;
    for(auto e:E[p])if(!(b>>e&1))
    {
        if(W[e]!=1)dfs0(U[e]^V[e]^p,r,a<<1,b|1u<<e);
        if(W[e])dfs0(U[e]^V[e]^p,r,a<<1|1,b|1u<<e);
    }
}
uint R[1u<<17|1],Sol[1u<<17|1];
uint Dp[18][1u<<17|1],n;bol Upd[18][1u<<17|1];
uint Q[18][1u<<17|1],Qc[18];
uint Id1[41000005],W1[41000005],tp1;
uint Id2[2500005],W2[2500005],Sol2[2500005],tp2;
voi tryupd(uint d,uint s,uint v)
{
    if(v>Dp[d][s])
    {
        Id1[tp1]=d<<(n-1)|s,W1[tp1]=Dp[d][s],tp1++,Dp[d][s]=v;
        if(d+R[s]<v)Id2[tp2]=s,W2[tp2]=R[s],Sol2[tp2]=Sol[s],Sol[s]=d,tp2++,R[s]=v-d;
        if(d&&!Upd[d][s])Upd[d][s]=true,Q[d][Qc[d]++]=s;
    }
}
uint T1[1u<<20|1],T2[1u<<20|1];
voi dfs(uint d,uint s)
{
    uint lst=-1;
    for(uint e=End[s|1u<<d];~e;std::swap(lst,Last[e]),std::swap(lst,e))
    {
        T1[e]=tp1,T2[e]=tp2;
        for(uint t=(1u<<(n-1))-1;~t;t--)t&=~S[e],tryupd(d,S[e]|t,R[t]+d);
    }
    End[s|1u<<d]=lst;
    if(d<n-1)dfs(d+1,s),dfs(d+1,s|1u<<d);
    while(Qc[d])Qc[d]--,Upd[d][Q[d][Qc[d]]]=false,tryupd(d-1,Q[d][Qc[d]],Dp[d][Q[d][Qc[d]]]);
}
std::vector<std::pair<uint,uint> >Ans;
voi dfs2(uint d,uint s,uint&wil,uint&w,uint&f)
{
    if(d<n-1)dfs2(d+1,s|1u<<d,wil,w,f),dfs2(d+1,s,wil,w,f);
    if(!~f)for(uint e=End[s|1u<<d];~e;e=Last[e])
    {
        while(tp1>T1[e])tp1--,Dp[Id1[tp1]>>(n-1)][Id1[tp1]&((1u<<(n-1))-1)]=W1[tp1];
        while(tp2>T2[e])tp2--,R[Id2[tp2]]=W2[tp2],Sol[Id2[tp2]]=Sol2[tp2];
        if((wil&S[e])==S[e]&&Dp[d][wil]<w&&R[wil^S[e]]+d==w)
        {
            Ans.push_back({s,e}),wil^=S[e],w-=d-Sol[wil],f=Sol[wil];
            if(f==d)f=-1;
        }
    }
    if(f==d-1)f=-1;
}
voi solve()
{
    scanf("%u",&n);for(uint i=0;i<n;i++)E[i].clear();
    for(uint i=0;i<n-1;i++)scanf("%u%u%u",U+i,V+i,W+i),E[U[i]].push_back(i),E[V[i]].push_back(i);
    for(uint i=0;i<(1u<<n);i++)End[i]=-1;
    cnt=0;for(uint i=0;i<n;i++)dfs0(i,i,1,0);
    for(uint i=0;i<n;i++)for(uint j=0;j<(1u<<(n-1));j++)Dp[i][j]=0;
    for(uint i=0;i<(1u<<(n-1));i++)R[i]=Sol[i]=0;
    tp1=tp2=0,dfs(0,0);
    uint s=(1u<<(n-1))-1;uint w=Dp[0][s];uint f=-1;printf("%u\n",w+1);Ans.clear(),dfs2(0,0,s,w,f);if(w)exit(233);
    for(uint i=0;i<n;i++)
    {
        for(uint j=0;j<n;j++)Go[i][j]=-1;
        Go[i][i]=n;std::vector<uint>Q{i};
        while(Q.size())
        {
            uint p=Q.back();Q.pop_back();
            for(auto e:E[p])if(!~Go[i][U[e]^V[e]^p])Q.push_back(U[e]^V[e]^p),Go[i][Q.back()]=e;
        }
    }
    for(auto s:Ans)
    {
        uint u=From[s.second],v=To[s.second],w=s.first;while(u!=v)W[Go[v][u]]=w&1,w>>=1,u^=U[Go[v][u]]^V[Go[v][u]];
    }
    printf("%u\n",(uint)Ans.size());
    for(uint i=0;i<n-1;i++)printf("%c%c","10"[!W[i]]," \n"[i==n-2]);
    for(auto s:Ans)printf("%u %u\n",From[s.second],To[s.second]);
}
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#endif
    uint t;scanf("%u%*u",&t),puts("1");
    while(t--)solve();
    return 0;
}

// 那就是希望。
// 即便需要取模,也是光明。

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 32464kb

input:

1000 0
4
0 2 0
2 3 0
2 1 0
4
3 2 1
0 2 1
1 2 2
4
0 2 2
0 1 0
3 0 0
4
1 2 1
3 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1
0 2
1 3
4
1
0 1 1
1 3
4
1
0 0 0
0 3
4
1
0 0 0
1 2
4
2
0 0 1
3 1
0 2
4
1
0 1 0
0 2
3
1
0 0 0
1 2
4
1
0 1 0
2 3
4
1
0 0 0
1 3
4
2
0 0 1
1 3
0 2
4
1
0 1 0
0 2
4
...

result:

ok Accepted. Good Job!

Subtask #2:

score: 10
Accepted

Test #3:

score: 10
Accepted
time: 9ms
memory: 36664kb

input:

3000 3
4
0 1 1
0 3 1
0 2 0
4
3 2 0
0 1 1
1 2 0
4
1 0 0
2 3 1
3 1 0
4
2 1 0
2 0 1
3 0 0
4
2 3 1
3 0 1
2 1 0
4
2 3 1
2 1 1
2 0 1
4
0 2 0
1 0 0
3 0 0
4
3 1 1
0 2 0
2 3 0
6
4 0 0
3 1 1
2 3 0
0 5 1
1 5 0
4
2 3 1
3 0 0
3 1 1
4
0 3 0
1 2 0
0 2 1
4
0 2 1
3 1 0
2 1 1
4
2 0 0
2 3 1
1 3 0
6
3 1 0
3 4 1
4 0 1
2...

output:

1
4
2
1 1 0
1 3
0 2
4
1
0 1 0
3 0
4
1
0 1 0
0 2
4
1
0 1 0
1 3
4
1
1 1 0
1 0
3
1
1 1 1
0 3
3
1
0 0 0
1 3
4
1
1 0 0
0 1
6
1
0 1 0 1 0
2 4
4
2
1 0 1
1 2
0 3
4
1
0 0 1
1 3
4
1
1 0 1
3 0
4
1
0 1 0
0 1
5
1
0 1 1 1 1
5 2
4
2
1 0 0
1 3
0 2
4
1
1 0 1
0 3
3
1
1 1 1
0 3
3
1
0 1
0 2
4
2
0 1 0
2 1
0 3
5
2
0 0 0 ...

result:

ok Accepted. Good Job!

Test #4:

score: 10
Accepted
time: 6ms
memory: 34544kb

input:

3000 3
3
0 1 0
1 2 0
4
2 1 1
0 2 0
0 3 1
6
3 4 1
1 4 0
1 5 1
2 1 1
3 0 0
4
0 2 1
1 2 0
1 3 1
4
0 3 1
2 0 1
1 2 0
6
1 2 0
0 3 0
2 5 0
0 2 1
4 2 0
4
2 0 0
2 1 1
3 1 1
4
1 0 1
1 2 0
3 0 1
4
1 3 0
2 1 1
0 2 0
4
1 3 0
2 1 0
1 0 0
4
3 1 0
2 3 0
0 1 1
4
1 0 0
2 0 0
3 0 0
4
2 1 1
1 0 1
2 3 0
4
3 0 1
1 0 0
2...

output:

1
3
1
0 0
0 2
4
1
1 0 1
1 3
6
2
1 0 1 1 0
2 5
0 1
4
1
1 0 1
0 3
4
1
1 1 0
1 3
5
2
0 0 0 1 0
3 5
1 4
4
1
0 1 1
0 3
4
1
1 0 1
2 3
4
1
0 1 0
0 3
3
1
0 0 0
0 3
4
1
0 0 1
2 0
3
1
0 0 0
2 3
4
1
1 1 0
3 0
4
1
1 0 0
1 2
6
1
1 0 0 1 0
1 3
4
1
0 1 1
1 3
4
1
0 1 0
2 3
4
1
0 0 1
0 2
4
1
0 0 0
0 1
4
1
0 1 0
1 3
...

result:

ok Accepted. Good Job!

Subtask #3:

score: 10
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #5:

score: 10
Accepted
time: 14ms
memory: 36572kb

input:

3000 4
4
2 0 0
1 2 0
1 3 0
4
1 2 2
0 2 2
3 2 2
4
3 1 2
3 2 0
0 2 0
4
0 3 2
2 1 2
0 1 2
4
0 1 0
3 0 0
0 2 2
4
2 0 0
2 1 0
3 0 0
6
0 3 2
5 0 2
5 2 2
1 4 2
4 3 2
4
0 3 0
3 1 0
0 2 0
4
1 0 2
2 0 2
3 2 2
4
2 1 2
1 0 2
0 3 2
6
5 0 2
0 2 2
0 4 2
1 0 2
0 3 2
6
4 5 2
0 1 2
0 3 2
4 3 2
5 2 2
4
1 3 0
3 2 0
1 0...

output:

1
4
1
0 0 0
0 3
4
2
0 1 0
0 3
1 2
4
1
0 0 0
0 1
4
1
0 0 0
2 3
4
2
0 0 1
2 3
0 1
4
1
0 0 0
1 3
6
1
0 0 0 0 0
1 2
4
1
0 0 0
1 2
4
1
0 0 0
1 3
4
1
0 0 0
2 3
5
2
0 1 0 0 1
3 5
1 4
6
1
0 0 0 0 0
1 2
4
1
0 0 0
0 2
6
1
0 0 0 0 0
1 5
4
1
0 0 0
0 3
4
1
0 0 0
0 1
4
1
0 0 0 0 0
0 5
4
2
0 1 0
3 2
0 1
4
2
0 1 0
...

result:

ok Accepted. Good Job!

Test #6:

score: 10
Accepted
time: 15ms
memory: 38664kb

input:

3000 0
6
1 3 2
0 4 0
1 4 2
3 5 1
0 2 0
6
0 5 0
0 4 1
0 2 0
3 0 0
1 0 0
6
4 1 2
2 1 1
5 0 2
5 3 1
2 3 0
4
2 0 0
1 0 2
1 3 0
4
2 3 1
0 1 1
2 1 0
4
0 3 1
1 0 2
2 3 0
4
1 3 1
2 3 0
0 1 2
6
1 0 1
4 1 1
5 1 1
3 1 1
2 1 2
4
0 3 1
1 3 2
1 2 1
4
1 2 1
0 2 0
3 1 1
6
0 2 1
1 2 1
0 5 0
2 4 1
2 3 1
6
3 2 1
0 2 0...

output:

1
6
1
0 0 0 1 0
2 5
5
2
0 1 0 0 0
4 5
1 3
6
1
0 1 0 1 0
0 4
4
1
0 0 0
2 3
4
1
1 1 0
0 3
4
1
1 0 0
1 2
4
1
1 0 0
0 2
5
2
1 1 1 1 0
3 5
2 4
4
1
1 0 1
0 2
4
1
1 0 1
0 3
6
2
1 1 0 1 1
3 4
5 1
6
1
1 0 1 0 1
1 4
4
2
1 0 1
1 3
0 2
4
1
0 0 0
0 3
6
1
1 0 0 1 1
1 3
3
1
0 0 0
1 3
3
1
0 0 0
2 3
3
1
0 0
0 1
5
2
...

result:

ok Accepted. Good Job!

Subtask #4:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #7:

score: 10
Accepted
time: 39ms
memory: 44864kb

input:

3000 3
8
1 2 1
3 7 0
7 0 1
7 4 0
6 5 0
6 4 1
2 0 0
5
3 1 0
3 2 1
0 1 0
4 0 1
5
3 2 0
4 0 0
4 1 0
2 0 1
6
5 4 1
4 1 1
4 2 1
0 4 1
4 3 1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 0
0 5
6
1
0 1 1 0 0
0 3
6
1
0 0 1 0 1
0 2
5
1
0 0 0 1 0
0 4
6
1
1 1 0 1 0
4 2
7
3
0 1 1 1 1 0 0
0 6...

result:

ok Accepted. Good Job!

Subtask #5:

score: 10
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #9:

score: 10
Accepted
time: 49ms
memory: 40944kb

input:

3000 4
6
2 5 2
3 4 0
2 1 0
0 1 0
0 3 2
6
2 0 2
1 4 0
5 3 0
0 4 2
0 3 0
8
4 6 2
2 5 2
1 0 2
5 0 2
1 4 2
4 7 2
3 7 2
6
0 4 0
5 2 0
2 1 0
1 0 2
5 3 2
8
5 6 2
6 3 2
6 7 2
7 4 2
2 6 2
1 4 2
0 4 2
6
1 5 0
2 1 0
3 1 0
5 0 0
2 4 0
6
5 1 2
0 5 0
2 4 2
2 5 0
4 3 0
8
7 6 0
6 1 0
2 0 0
7 3 0
3 2 0
4 0 0
5 1 0
6...

output:

1
6
1
0 0 0 0 0
4 5
6
2
1 0 0 0 0
2 5
0 1
8
2
0 1 0 0 0 0 0
2 3
4 6
6
1
0 0 0 0 0
3 4
7
2
0 0 0 0 0 1 1
0 5
2 3
5
1
0 0 0 0 0
0 4
6
2
1 0 0 0 0
1 3
0 5
8
1
0 0 0 0 0 0 0
4 5
6
1
0 0 0 0 0
2 5
5
1
0 0 0 0 0
2 4
8
2
0 0 0 1 0 0 0
5 6
0 1
8
2
0 0 1 0 0 0 0
2 7
3 5
6
1
0 0 0 0 0
3 5
6
1
0 0 0 0 0
2 4
4
...

result:

ok Accepted. Good Job!

Test #10:

score: 10
Accepted
time: 44ms
memory: 42960kb

input:

3000 0
6
4 0 0
1 4 1
5 3 0
3 2 1
0 5 1
8
1 7 0
6 1 0
4 2 0
4 1 1
5 4 0
4 3 0
0 4 1
8
3 1 0
2 3 0
3 0 0
4 7 0
5 7 0
7 6 0
7 3 0
6
5 2 2
4 0 2
0 3 2
5 4 2
1 3 2
4
2 3 1
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
1 7
4 0
4
1
0 1 0
0 2
7
2
1 1 1 0 0 1 1
4 3
6 5
7
2
0 1 1 0 1 1
3 6
1 5
5
2
0 0 1 0 0 0 0
0 7
4 5
5
2
1 ...

result:

ok Accepted. Good Job!

Test #12:

score: 10
Accepted
time: 189ms
memory: 56132kb

input:

3000 3
8
4 5 1
6 4 0
3 7 1
1 6 1
0 2 1
5 7 0
1 2 0
8
6 1 1
1 4 0
6 7 0
6 0 1
2 1 1
6 3 0
5 0 1
8
1 0 0
7 3 0
1 4 0
2 1 0
6 5 0
3 4 1
5 2 1
8
0 4 1
5 2 1
3 0 0
7 0 1
0 2 0
0 1 1
6 3 1
7
3 6 1
1 0 0
0 4 1
5 2 1
5 4 0
5 6 0
8
0 1 1
7 4 0
1 2 1
0 6 0
4 5 0
6 3 1
1 4 1
11
1 3 0
3 0 0
3 5 1
8 3 0
9 8 1
3 ...

output:

1
8
1
1 0 1 1 1 0 0
0 3
7
2
1 0 0 1 1 0 1
5 4
3 7
7
1
0 0 0 0 0 1 1
6 7
7
3
1 1 0 1 0 1 1
1 7
4 6
0 5
7
2
1 0 1 1 0 0
2 1
5 3
7
2
1 0 1 0 0 1 1
3 7
4 5
8
4
0 0 1 0 1 0 0 1 1 0
4 7
9 10
6 5
0 2
8
2
0 1 0 0 1 0 0
1 6
0 7
8
1
0 1 1 1 1 0 0
7 6
7
3
0 0 0 0 1 0 1
4 7
2 6
0 1
7
1
1 0 0 1 0 0
0 6
10
2
1 1 ...

result:

ok Accepted. Good Job!

Subtask #7:

score: 5
Accepted

Test #13:

score: 5
Accepted
time: 259ms
memory: 59784kb

input:

3000 1
11
2 5 0
10 2 0
6 2 0
2 8 0
0 2 0
2 1 0
2 4 0
2 9 0
2 3 0
7 2 0
11
7 8 0
6 4 0
1 6 0
2 8 0
8 0 0
6 3 0
9 5 0
5 8 0
1 2 0
9 10 0
8
1 4 0
2 3 0
6 5 0
6 7 0
2 4 0
7 3 0
1 0 0
8
4 0 0
0 5 0
7 2 0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
10
2
0 0 1 0 0 0 1 0 0 0
3 7
4 9
8
2
0 0 0 1...

result:

ok Accepted. Good Job!

Test #15:

score: 15
Accepted
time: 1283ms
memory: 83416kb

input:

3000 2
8
0 5 2
2 6 2
2 3 2
4 3 2
1 5 2
1 6 2
7 4 2
8
2 3 2
1 5 2
6 7 2
1 4 2
6 0 2
2 5 2
3 7 2
7
4 3 2
0 6 2
6 1 2
2 4 2
4 5 2
5 6 2
6
2 0 2
1 2 2
2 4 2
4 3 2
2 5 2
7
6 4 2
1 4 2
5 4 2
3 6 2
0 2 2
4 2 2
8
3 4 2
6 3 2
2 3 2
5 3 2
0 7 2
3 0 2
1 3 2
8
1 5 2
1 2 2
2 4 2
1 6 2
0 1 2
7 1 2
3 2 2
8
7 5 2
7...

output:

1
8
1
0 0 0 0 0 0 0
0 7
8
1
0 0 0 0 0 0 0
0 4
6
2
0 0 1 1 0 0
1 3
0 6
6
2
0 0 0 1 0
3 5
0 1
7
2
0 0 0 0 1 0
0 3
1 5
7
3
0 1 0 0 0 0 1
1 7
5 6
2 4
6
2
1 0 1 0 0 0 1
3 7
0 6
8
2
0 0 1 0 0 0 0
0 3
6 7
11
1
0 0 0 0 0 0 0 0 0 0
5 9
8
2
0 1 0 0 0 0 0
3 7
2 6
8
2
0 0 0 0 0 0 1
2 7
4 6
8
2
0 1 0 0 0 0 0
3 6...

result:

ok Accepted. Good Job!

Test #16:

score: 15
Accepted
time: 1296ms
memory: 84560kb

input:

3000 2
8
7 2 2
5 2 2
4 2 2
0 2 2
6 2 2
1 2 2
3 2 2
8
6 4 2
4 7 2
0 4 2
3 2 2
3 4 2
5 3 2
5 1 2
8
0 1 2
4 0 2
3 2 2
6 7 2
6 2 2
5 3 2
7 1 2
10
3 1 2
8 3 2
7 3 2
4 3 2
2 3 2
9 3 2
0 3 2
6 3 2
3 5 2
7
2 5 2
3 2 2
5 0 2
2 1 2
6 2 2
4 2 2
8
2 7 2
2 6 2
2 5 2
2 4 2
0 2 2
2 3 2
2 1 2
7
5 2 2
1 5 2
4 2 2
3 ...

output:

1
6
3
0 0 1 0 1 0 1
3 7
1 6
0 5
7
2
0 0 0 1 0 0 1
1 7
0 6
8
1
0 0 0 0 0 0 0
4 5
7
4
1 0 1 0 0 1 0 1 1
5 9
6 8
0 7
2 4
6
2
0 1 1 0 0 0
0 6
1 4
6
3
0 1 0 1 0 0 1
1 7
3 6
0 5
7
1
0 0 0 0 0 0
0 1
6
3
0 0 1 0 0 1
5 6
3 4
0 1
8
1
0 0 0 0 0 0 0
2 3
7
1
0 0 0 0 0 0
3 5
8
2
0 0 0 0 0 1 0
1 7
0 5
7
1
0 0 0 0 ...

result:

ok Accepted. Good Job!

Subtask #9:

score: 10
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Test #17:

score: 10
Accepted
time: 363ms
memory: 67416kb

input:

3000 3
8
1 2 0
4 6 1
2 4 1
3 4 1
4 0 0
5 6 0
4 7 1
8
6 0 0
2 6 1
5 4 1
0 4 1
2 3 0
7 1 1
5 1 0
17
8 7 0
15 7 0
5 7 1
4 5 1
2 5 1
16 5 1
10 16 0
14 5 1
6 2 0
3 5 1
12 7 0
14 0 0
3 1 0
9 5 1
13 5 1
16 11 0
14
4 3 0
2 10 1
12 1 0
9 7 0
6 13 0
5 11 0
8 12 1
6 3 1
4 1 1
0 10 0
2 8 0
7 5 1
0 11 1
8
7 6 0
...

output:

1
7
2
0 1 1 1 0 0 1
7 5
0 1
8
1
0 1 1 1 0 1 0
3 7
10
4
0 0 1 1 1 1 0 1 0 1 0 0 0 1 1 0
13 15
5 11
1 6
8 12
14
1
0 1 0 0 0 0 1 1 1 0 0 1 1
9 13
7
2
0 0 1 0 0 1 0
1 5
2 7
7
2
1 1 1 1 1 1 0
0 7
6 3
8
2
1 1 1 0 1 1 0
2 5
3 0
7
3
1 1 1 0 0 1 1
0 5
2 6
7 1
8
4
1 0 1 0 0 1 0 0 0 1
0 6
3 10
8 2
4 9
8
4
1 0 ...

result:

ok Accepted. Good Job!

Test #18:

score: 10
Accepted
time: 358ms
memory: 68680kb

input:

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

output:

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

result:

ok Accepted. Good Job!

Subtask #10:

score: 10
Accepted

Dependency #5:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Test #19:

score: 10
Accepted
time: 516ms
memory: 79556kb

input:

3000 0
8
3 2 0
0 2 1
4 1 1
5 4 0
3 6 1
7 5 1
6 1 0
8
3 1 2
4 5 0
1 6 2
5 0 0
3 2 0
7 5 2
2 4 0
8
4 7 1
5 3 0
4 0 1
6 5 1
3 1 2
2 4 1
3 4 2
11
3 2 0
8 2 0
1 5 2
0 8 2
3 9 2
0 7 2
4 3 0
6 9 2
6 5 0
10 9 2
11
10 1 2
8 4 2
8 7 2
0 4 2
8 6 2
3 9 2
2 9 2
2 1 2
0 3 2
5 8 2
7
3 5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