QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#326025#6315. 填数游戏littlecat12 660ms112456kbC++143.4kb2024-02-12 08:08:092024-02-12 08:08:09

Judging History

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

  • [2024-02-12 08:08:09]
  • 评测
  • 测评结果:12
  • 用时:660ms
  • 内存:112456kb
  • [2024-02-12 08:08:09]
  • 提交

answer

// #define DEBUG
int TIMER=20;
#define TIME if(!TIMER--)exit(0);
#pragma GCC optimize("O3")
#include <iostream>
#include <vector>
using namespace std; const int mx=1000000; typedef pair<int,int> pi;
#define pb push_back
#define f first
#define s second

pi s1[mx],s2[mx]; bool sz1[mx],edge[mx]; vector<int> adj0[mx]; //initial sets
pi e[mx],es[mx]; vector<int> adj[mx]; //graph

int cntE,cntV; bool vis[mx]; //components
void dfs1(int c)
{
    if(vis[c]) return; cntV++, cntE+=adj[c].size(), vis[c]=1;
    for(int t:adj[c]) dfs1(e[t].f+e[t].s-c);
}

bool cycle[mx],cycledone; int cpar[mx],rt;
void dfs2(int c, int p)
{
    for(int t:adj[c]) if(t!=p)
    {
        int k=e[t].f+e[t].s-c; if(cpar[k]==-1) cpar[k]=c, dfs2(k,t); else if(!cycledone)
        {rt=c,cycledone=1; while(1) {cycle[rt]=1; if(rt==k) break; rt=cpar[rt];}}
    }
}
bool vis3[mx]; int cnt3;
void dfs3(int c, int p)
{
    if(vis3[c]) return; vis3[c]=1; for(int t:adj[c])
    {
        int k=e[t].f+e[t].s-c; if(k==p) continue; dfs3(k,c);
        if(!cycle[k]) cnt3+=k==es[t].f||k==es[t].s;
    }
}
vector<int> cv, cn;
void getcycle(int c)
{
    cn.pb(c); if(c==rt&&!cv.empty()) return; for(int t:adj[c])
    {
        int k=e[t].f+e[t].s-c;
        if(cycle[k]&&!(!cv.empty()&&t==cv.back())) {cv.pb(t), getcycle(k); break;}
    }
}

int solve()
{
#ifdef DEBUG
cout<<"Start\n"<<flush;
#endif
    //note: swap m/n
    int m,n,ans=0; cin>>m>>n;
    for(int i=0; i<n; i++) adj0[i].clear(),adj[i].clear(), vis[i]=vis3[i]=0, cycle[i]=0, cpar[i]=-1;
    for(int i=0; i<m; i++) edge[i]=1;
    //input and delete |T|=1
{
    int a,b;
    for(int i=0; i<m; i++) {int c; cin>>c>>a; if(c==2) cin>>b; else b=0; s1[i]=pi(a-1,b-1);}
    for(int i=0; i<m; i++) {int c; cin>>c>>a; if(c==2) cin>>b; else b=0; s2[i]=pi(a-1,b-1);
        sz1[i]=2-c, adj0[a-1].pb(i); if(c==2) adj0[b-1].pb(i);}
    vector<int> rm; for(int i=0; i<m; i++) if(sz1[i]) rm.pb(i);
    while(!rm.empty())
    {
        int i=rm.back(); rm.pop_back(); if(!edge[i]) continue; if(s2[i].f==-1) return -1;
        ans+=s2[i].f==s1[i].f||s2[i].f==s1[i].s, edge[i]=0;
#ifdef DEBUG
cout<<"Assign "<<i<<' '<<s2[i].f<<" ("<<s2[i].s<<")\n";
#endif
        for(int j:adj0[s2[i].f]) {if(s2[j].f==s2[i].f) s2[j].f=s2[j].s; s2[j].s=-1, rm.pb(j);}
    }
    int E=0;
    for(int i=0; i<m; i++) if(edge[i]) adj[s2[i].f].pb(E),adj[s2[i].s].pb(E), e[E]=s2[i],es[E++]=s1[i];
    m=E;
}
#ifdef DEBUG
cout<<m<<' '<<ans<<'\n'; for(int i=0; i<m; i++) cout<<e[i].f<<' '<<e[i].s<<' '<<es[i].f<<' '<<es[i].s<<'\n';
for(int i=0; i<n; i++) {cout<<i<<'\t'; for(int t:adj[i]) cout<<t<<' '; cout<<'\n';} cout<<flush;
#endif
for(int i=0; i<n; i++) if(!vis[i])
{
    //count edges
    cntE=cntV=0, dfs1(i); if(cntE>2*cntV) return -1;
    if(cntE==2*cntV)
    {
        //cycle with trees: explicit formula
        cycledone=0, cpar[i]=-2, dfs2(i,-1);
        cnt3=0, dfs3(rt,-1), ans+=cnt3;
        cv.clear(),cn.clear(), getcycle(rt);
        int A=0,B=0,C=0; for(int j=0; j<cv.size(); j++)
        {
            bool x1=cn[j]==es[cv[j]].f||cn[j]==es[cv[j]].s, x2=cn[j+1]==es[cv[j]].f||cn[j+1]==es[cv[j]].s;
            if(x1&&x2) C++; else if(x1) A++; else if(x2) B++;
        }
        ans+=min(min(A,B)+C,(A+B+C)/2);
    }
    else
    {
        //tree with variable root: dp
        ;
    }
}
    return ans;
}
int main()
{
    int T; cin.sync_with_stdio(0),cin.tie(0),cin>>T; while(T--) cout<<solve()<<'\n'<<flush;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 60904kb

input:

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

output:

0
0
0
0
0
0
8
-1
5
0
5
0
0
5
0
0
3
0
0
0

result:

wrong answer 1st numbers differ - expected: '4', found: '0'

Test #2:

score: 0
Wrong Answer
time: 8ms
memory: 63008kb

input:

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

output:

0
5
9
3
0
0
-1
0
5
0
0
0
0
0
0
0
0
5
0
0

result:

wrong answer 1st numbers differ - expected: '3', found: '0'

Test #3:

score: 0
Wrong Answer
time: 12ms
memory: 65064kb

input:

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

output:

6
0
0
0
-1
0
4
0
0
6
0
0
0
9
0
-1
0
0
0
0

result:

wrong answer 2nd numbers differ - expected: '1', found: '0'

Test #4:

score: 0
Wrong Answer
time: 15ms
memory: 63012kb

input:

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

output:

0
0
0
0
9
0
0
0
4
4
0
6
0
0
0
6
0
-1
0
0

result:

wrong answer 1st numbers differ - expected: '3', found: '0'

Test #5:

score: 0
Wrong Answer
time: 8ms
memory: 67076kb

input:

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

output:

3
4
0
0
0
6
0
0
6
0
0
0
0
0
5
0
6
0
0
0

result:

wrong answer 3rd numbers differ - expected: '1', found: '0'

Test #6:

score: 0
Wrong Answer
time: 7ms
memory: 63272kb

input:

1000
10 10
2 1 8
2 8 3
2 3 4
2 2 1
2 4 7
2 7 4
2 9 6
1 5
1 8
2 2 6
2 7 3
2 6 7
2 10 9
2 8 3
2 9 1
2 10 6
2 3 10
2 7 4
2 5 6
2 3 8
9 10
2 8 4
1 3
1 9
2 3 7
2 6 2
2 4 3
2 3 7
2 1 4
2 1 7
2 5 2
2 5 4
2 5 8
2 10 5
2 8 9
2 5 6
1 10
2 8 7
1 10
39 40
2 3 40
2 26 17
2 21 27
2 5 9
1 24
2 19 6
2 25 18
2 18 29...

output:

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

result:

wrong answer 13th numbers differ - expected: '-1', found: '0'

Test #7:

score: 4
Accepted
time: 7ms
memory: 61000kb

input:

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

output:

3
4
3
4
2
3
4
3
2
4
3
3
3
5
2
3
5
5
5
3
2
3
3
2
13
4
4
3
1
3
2
2
3
4
4
3
4
2
4
3
4
4
2
3
4
4
3
1
1
3
3
1
4
4
24
4
4
2
4
3
2
2
2
1
3
4
4
2
1
5
4
3
4
0
4
4
4
3
2
4
4
4
4
5
1
3
4
3
3
2
3
2
3
3
4
4
3
1
3
4
3
2
3
3
1
2
35
1
4
3
3
4
4
2
3
3
3
2
4
3
4
3
3
1
3
2
2
17
3
4
2
3
4
11
4
4
3
4
2
9
2
5
2
2
3
3
4
3...

result:

ok 1000 numbers

Test #8:

score: 0
Wrong Answer
time: 13ms
memory: 65028kb

input:

1000
1 10
1 7
1 7
2 10
1 8
1 3
1 8
1 3
2 10
1 1
1 9
1 1
1 9
5 10
1 7
1 6
1 4
1 3
1 10
1 7
1 6
1 4
1 3
1 10
29 40
1 9
1 15
1 29
1 20
1 8
1 30
1 27
1 7
1 24
1 8
1 23
1 17
1 10
1 28
1 26
1 19
1 15
1 33
1 16
1 14
1 10
1 30
1 20
1 40
1 22
1 10
1 31
1 38
1 5
2 28 9
2 15 6
2 39 29
2 20 31
2 8 38
2 30 25
1 ...

output:

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

result:

wrong answer 5th numbers differ - expected: '8', found: '3'

Test #9:

score: 0
Wrong Answer
time: 11ms
memory: 60876kb

input:

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

output:

2
3
6
4
3
1
8
4
4
-1
4
7
5
2
3
3
1
4
2
13
4
6
14
3
5
3
6
3
2
6
3
6
8
6
7
5
7
6
2
4
5
5
4
2
3
7
7
2
33
3
0
3
4
4
5
4
4
3
7
5
8
7
6
5
6
6
2
3
4
4
4
7
6
3
5
5
6
3
5
7
5
6
4
6
6
4
3
2
6
4
4
6
3
16
4
7
5
3
7
5
5
2
-1
3
1
5
7
7
5
4
3
3
2
8
4
3
1
3
-1
4
18
4
4
3
4
4
6
7
4
6
5
5
5
4
6
-1
7
6
4
2
2
6
9
3
4
6...

result:

wrong answer 1st numbers differ - expected: '3', found: '2'

Test #10:

score: 0
Wrong Answer
time: 4ms
memory: 63068kb

input:

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

output:

5
6
6
4
5
6
5
5
5
4
4
5
4
13
4
5
3
5
5
5
6
15
5
6
3
6
3
5
4
4
4
4
6
5
13
3
4
5
4
7
6
7
4
3
6
4
6
4
5
3
5
4
7
4
5
6
5
4
4
4
5
6
5
8
4
5
6
5
4
5
7
5
3
5
9
6
5
10
6
5
4
5
5
5
5
4
3
3
4
6
4
5
6
4
6
9
4
4
5
3
5
4
4
4
5
3
4
3
3
3
11
4
5
4
4
5
3
3
5
5
5
4
7
6
5
5
4
7
5
5
5
6
5
3
4
20
6
4
3
6
5
5
5
5
5
3
5
...

result:

wrong answer 1st numbers differ - expected: '6', found: '5'

Test #11:

score: 0
Wrong Answer
time: 15ms
memory: 64968kb

input:

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

output:

3
7
5
6
3
4
6
5
5
5
7
4
5
18
6
3
5
6
5
4
3
4
5
6
7
4
5
5
4
4
4
4
5
5
7
3
3
6
4
4
6
7
6
4
4
5
6
4
5
6
4
6
5
4
3
4
8
4
4
4
4
5
4
6
5
4
3
5
5
3
5
4
5
5
7
5
6
4
5
5
-1
5
5
6
5
5
3
4
4
4
5
7
5
5
3
6
5
4
4
4
5
5
7
-1
4
6
6
5
4
4
4
5
6
3
6
4
6
4
3
7
5
4
4
4
5
6
8
4
4
4
5
5
5
4
5
7
13
6
4
6
3
4
6
16
5
12
5
...

result:

wrong answer 14th numbers differ - expected: '36', found: '18'

Test #12:

score: 0
Wrong Answer
time: 33ms
memory: 63048kb

input:

1000
89 100
2 7 10
2 44 79
2 90 72
2 81 82
2 97 98
1 26
2 12 11
2 19 22
2 75 76
2 87 57
2 93 20
2 14 15
1 18
2 52 56
2 63 65
1 52
2 19 69
2 17 30
1 80
2 87 88
2 32 79
2 65 57
2 10 99
2 74 71
1 90
2 61 62
2 61 40
2 15 59
2 78 53
1 71
2 82 36
2 29 8
2 17 18
2 92 67
2 81 63
2 4 5
2 51 54
2 14 13
1 62
2...

output:

18
19
-1
20
11
18
13
14
14
19
15
51
14
10
17
18
18
13
17
8
13
15
11
-1
11
-1
20
14
47
-1
13
15
9
12
-1
35
24
11
25
-1
11
23
-1
-1
16
18
-1
-1
15
10
12
11
-1
-1
13
23
17
9
13
23
26
-1
10
13
14
16
19
11
9
45
17
16
10
15
16
12
13
17
14
10
12
12
14
-1
12
14
-1
9
15
13
12
12
10
16
13
13
19
12
12
13
15
14...

result:

wrong answer 1st numbers differ - expected: '38', found: '18'

Test #13:

score: 0
Wrong Answer
time: 32ms
memory: 61128kb

input:

1000
94 100
2 52 4
1 59
1 47
1 59
2 42 94
2 12 13
2 71 87
2 60 59
2 57 47
2 94 70
1 64
2 12 27
2 77 94
2 50 35
1 5
2 70 58
2 64 56
2 67 68
2 21 29
1 26
2 100 73
2 92 93
1 73
2 71 72
2 38 36
2 50 20
1 74
2 47 87
1 4
1 76
2 92 99
2 82 64
2 48 49
2 15 14
2 38 69
1 51
2 55 42
1 68
1 45
2 21 16
1 30
2 91...

output:

25
-1
15
10
15
7
9
12
15
8
20
12
21
21
-1
20
21
14
14
36
10
21
-1
15
11
20
-1
16
12
22
-1
20
18
13
53
12
18
15
11
14
13
21
17
15
19
12
-1
13
-1
17
8
18
14
13
9
18
16
10
22
12
13
15
12
-1
11
18
17
-1
18
10
-1
15
12
9
-1
18
17
-1
14
8
15
10
12
-1
12
18
14
11
-1
18
-1
19
15
49
16
19
13
38
10
18
26
16
1...

result:

wrong answer 1st numbers differ - expected: '41', found: '25'

Test #14:

score: 0
Wrong Answer
time: 102ms
memory: 75588kb

input:

1000
88 90
2 59 42
1 45
2 68 83
2 36 2
2 89 70
1 7
1 8
2 67 55
2 81 47
2 76 36
1 68
2 86 27
1 8
1 12
1 4
2 64 21
2 11 1
2 6 69
2 39 58
2 39 40
1 3
2 39 76
1 62
2 43 69
1 53
1 79
2 78 65
2 85 1
1 75
2 47 87
2 26 41
2 17 38
1 2
2 25 41
2 86 71
1 37
2 31 80
1 14
2 47 12
2 66 78
2 28 83
1 57
1 69
2 53 6...

output:

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

result:

wrong answer 6th numbers differ - expected: '0', found: '-1'

Test #15:

score: 4
Accepted
time: 112ms
memory: 94692kb

input:

1000
86 90
1 2
2 2 79
2 4 89
2 55 4
2 12 6
2 6 70
2 7 9
2 8 39
2 30 10
2 10 35
2 70 8
2 12 13
1 13
2 14 35
2 15 21
2 42 16
1 28
1 18
1 19
2 75 20
2 21 5
2 81 22
2 55 23
2 24 19
1 25
1 62
1 27
1 28
2 59 29
2 31 30
2 32 31
1 32
1 33
1 35
1 35
2 36 70
2 85 29
2 39 38
1 39
1 40
2 18 41
1 42
2 84 44
2 44...

output:

22
25
37
40
30
30
36
26
23
36
29
29
17
27
33
22
37
20
36
26
35
29
40
26
21
40
26
19
33
27
24
37
20
21
29
23
23
22
36
36
34
27
22
39
38
40
39
20
22
18
35
27
36
25
32
21
40
36
21
36
25
19
27
38
37
27
17
25
39
23
25
38
26
26
31
37
27
37
36
17
23
21
23
28
37
27
20
38
29
22
21
20
23
41
22
38
24
22
26
26
...

result:

ok 1000 numbers

Test #16:

score: 4
Accepted
time: 118ms
memory: 94448kb

input:

1000
90 90
2 25 2
2 27 3
2 85 4
2 5 4
2 19 6
2 6 7
2 50 7
2 9 69
1 10
1 11
1 11
1 13
2 14 16
1 15
1 16
2 88 16
1 26
2 76 19
2 19 20
1 20
1 22
2 53 22
2 26 24
1 25
2 25 26
2 8 61
1 23
2 66 29
2 21 30
1 31
2 32 1
2 67 32
2 56 34
1 34
2 36 35
1 36
2 37 40
2 20 39
1 40
2 65 41
2 64 42
2 74 54
2 24 44
2 ...

output:

21
37
29
38
19
27
36
38
23
21
23
38
37
24
19
23
32
27
37
39
18
25
30
28
25
28
24
29
21
32
18
26
34
27
39
29
31
21
21
29
22
31
37
19
27
25
20
36
27
22
37
26
30
24
37
27
35
36
41
27
39
40
16
19
26
24
21
21
37
36
256
36
37
21
37
15
24
24
23
19
39
29
27
38
26
28
38
26
26
40
38
38
19
27
28
38
21
28
20
38...

result:

ok 1000 numbers

Test #17:

score: 0
Wrong Answer
time: 91ms
memory: 70356kb

input:

1000
76 90
1 3
1 83
1 67
1 28
1 17
1 63
1 16
1 13
1 27
1 75
1 12
1 85
1 19
1 40
1 30
1 32
1 58
1 20
1 83
1 72
1 50
1 11
1 53
1 39
1 3
1 58
1 71
1 31
1 6
1 35
1 20
1 62
1 43
1 63
1 32
1 51
1 55
1 73
1 33
1 8
1 34
1 21
1 55
1 44
1 50
1 81
1 84
1 88
1 65
1 53
1 28
1 40
1 14
1 77
1 4
1 87
1 13
1 89
1 11...

output:

-1
11
14
20
-1
16
15
17
19
5
-1
9
10
15
6
20
15
13
9
10
4
11
8
14
14
16
13
-1
-1
8
12
12
11
8
7
61
4
14
9
-1
17
9
11
-1
17
-1
8
12
11
9
12
11
8
9
17
13
14
8
3
15
-1
7
-1
-1
14
6
4
12
9
10
11
-1
13
15
6
10
8
8
8
16
-1
10
9
14
-1
9
-1
-1
12
18
12
-1
-1
13
10
11
11
-1
13
8
20
10
5
11
-1
-1
-1
-1
-1
15
...

result:

wrong answer 1st numbers differ - expected: '28', found: '-1'

Test #18:

score: 0
Wrong Answer
time: 94ms
memory: 70704kb

input:

1000
83 90
1 34
1 30
1 86
1 13
1 82
1 25
1 83
1 45
1 26
1 12
1 49
1 56
1 73
1 40
1 35
1 34
1 5
1 80
1 69
1 81
1 25
1 67
1 20
1 54
1 62
1 83
1 21
1 35
1 52
1 67
1 47
1 69
1 11
1 85
1 31
1 33
1 51
1 4
1 9
1 63
1 18
1 41
1 63
1 11
1 48
1 43
1 65
1 53
1 61
1 2
1 5
1 76
1 75
1 77
1 64
1 78
1 14
1 72
1 8
...

output:

18
8
-1
11
10
18
6
7
15
21
-1
13
14
13
10
13
9
10
6
-1
16
18
11
10
12
9
8
-1
10
16
15
5
10
5
8
7
21
13
12
12
15
13
12
21
10
13
13
12
9
6
-1
15
10
5
8
7
-1
-1
11
12
9
13
13
6
10
12
9
9
23
11
14
-1
12
13
12
9
-1
10
7
10
18
10
9
-1
15
7
11
16
10
12
18
15
-1
10
9
18
8
6
11
11
8
5
-1
17
13
-1
9
10
7
11
-...

result:

wrong answer 1st numbers differ - expected: '32', found: '18'

Test #19:

score: 0
Wrong Answer
time: 69ms
memory: 68616kb

input:

1000
62 90
1 59
2 46 10
2 85 2
2 79 41
2 34 88
2 49 7
2 66 19
2 77 75
2 26 86
2 68 13
2 71 85
2 11 29
2 65 74
2 80 19
2 87 48
2 17 27
2 21 46
1 44
2 30 27
1 20
2 86 58
2 85 40
2 40 36
2 1 27
2 74 44
1 72
2 14 12
2 18 29
2 39 33
2 66 19
2 90 60
2 47 62
2 52 90
2 12 80
2 68 75
2 51 29
2 1 57
1 61
2 43...

output:

24
29
-1
-1
16
7
-1
25
-1
22
22
17
11
23
12
29
25
17
-1
21
12
25
22
26
13
17
10
25
-1
-1
8
33
22
23
-1
-1
18
-1
24
20
16
20
22
-1
29
24
23
-1
32
26
27
21
19
20
10
23
15
-1
13
17
22
-1
-1
27
18
21
-1
-1
21
21
19
5
24
-1
31
17
30
-1
21
-1
-1
21
-1
25
26
-1
7
13
-1
23
17
24
-1
15
20
22
21
-1
21
13
19
1...

result:

wrong answer 1st numbers differ - expected: '48', found: '24'

Test #20:

score: 0
Wrong Answer
time: 62ms
memory: 66608kb

input:

1000
65 90
2 33 90
2 61 28
2 39 71
2 58 78
2 9 41
2 70 84
2 20 64
2 26 3
2 73 57
2 21 4
2 89 88
2 69 85
2 82 55
2 20 39
2 5 27
2 9 42
2 64 25
2 85 81
2 26 3
1 15
2 87 60
2 86 1
2 10 22
2 66 28
2 66 12
2 19 14
2 8 33
2 84 70
2 11 39
1 16
2 75 37
2 47 39
1 51
2 78 57
2 19 18
2 77 74
2 59 15
2 76 65
2 ...

output:

-1
10
14
13
19
22
-1
16
19
20
36
-1
20
15
23
18
19
17
22
12
-1
-1
-1
13
14
-1
15
18
15
33
-1
20
24
14
22
-1
-1
27
-1
23
18
-1
23
-1
-1
12
31
15
-1
25
37
12
15
-1
6
16
27
-1
10
15
29
-1
31
23
32
18
-1
12
10
-1
45
24
-1
-1
-1
28
22
-1
-1
12
26
34
28
-1
-1
28
33
-1
20
12
34
-1
22
11
27
18
17
18
-1
26
2...

result:

wrong answer 1st numbers differ - expected: '48', found: '-1'

Test #21:

score: 0
Wrong Answer
time: 97ms
memory: 70620kb

input:

1000
76 90
2 15 3
2 61 68
2 35 15
2 67 86
1 36
1 40
2 13 12
2 30 37
2 14 64
2 29 68
2 15 14
2 17 25
2 11 12
2 79 13
2 62 7
2 35 1
2 42 71
2 33 38
1 85
2 47 17
2 39 37
2 60 6
1 77
1 57
2 39 29
1 71
2 30 47
2 30 33
2 64 79
2 42 77
2 45 38
2 33 1
2 75 76
2 18 26
1 18
2 57 56
2 19 55
2 7 81
2 53 19
2 56...

output:

14
18
21
10
21
17
11
14
9
8
14
7
15
-1
19
14
19
20
15
13
23
11
10
-1
17
-1
14
18
14
17
11
18
9
14
18
10
18
13
13
13
16
16
12
14
15
17
15
17
16
-1
-1
18
18
12
10
12
10
15
15
21
8
11
14
18
17
13
-1
14
10
-1
12
13
12
4
16
18
12
18
17
16
17
12
20
17
18
20
23
-1
11
15
16
17
15
16
11
13
-1
10
21
15
14
11
...

result:

wrong answer 1st numbers differ - expected: '34', found: '14'

Test #22:

score: 0
Wrong Answer
time: 88ms
memory: 70620kb

input:

1000
80 90
2 48 50
2 20 23
2 82 8
1 4
1 40
2 69 59
2 13 67
2 6 86
2 3 74
2 9 38
1 9
1 79
1 18
2 15 14
1 31
2 77 21
2 33 72
2 56 39
2 32 33
2 90 89
2 86 83
2 90 13
2 34 26
2 23 68
1 50
2 65 83
1 77
2 79 69
2 25 26
2 44 43
2 74 84
2 13 12
1 62
1 71
2 26 70
2 2 83
2 7 20
2 23 1
2 11 12
2 78 7
1 58
1 65...

output:

16
21
12
-1
8
10
14
8
11
13
21
15
17
11
8
20
16
18
21
12
12
-1
10
17
15
16
-1
15
17
15
15
8
9
12
9
10
18
13
11
11
17
10
21
14
18
17
16
16
18
8
19
16
15
14
20
17
-1
8
8
9
10
11
17
10
15
9
18
12
18
9
16
17
11
9
16
10
9
12
19
17
14
18
19
11
15
12
16
13
8
19
14
-1
-1
11
10
17
16
15
16
12
14
12
7
10
13
1...

result:

wrong answer 1st numbers differ - expected: '33', found: '16'

Test #23:

score: 0
Wrong Answer
time: 647ms
memory: 112192kb

input:

1000
82 90
2 36 58
2 64 41
2 1 12
2 6 90
2 50 15
2 30 27
2 42 87
2 89 33
2 47 28
1 70
1 17
1 20
2 33 62
2 31 7
2 4 69
2 83 37
2 55 36
2 35 32
2 29 11
1 57
2 53 52
2 9 53
2 88 66
1 21
1 22
2 28 39
2 11 12
1 5
2 78 56
2 59 57
2 63 8
2 85 62
2 84 16
2 48 49
2 7 61
2 3 9
1 4
1 50
1 80
2 62 43
2 77 50
2 ...

output:

15
13
14
17
12
16
15
21
17
16
10
16
14
-1
17
23
12
11
-1
12
17
18
6
8
10
16
15
-1
14
-1
15
14
19
12
20
12
14
17
17
-1
12
11
10
9
12
12
25
16
15
16
13
14
13
13
9
11
20
16
15
12
15
18
14
15
18
13
-1
20
19
11
17
28
21
11
10
13
11
10
13
10
-1
17
17
16
9
12
10
-1
19
8
15
13
22
-1
16
9
11
-1
13
11
20
19
1...

result:

wrong answer 1st numbers differ - expected: '32', found: '15'

Test #24:

score: 0
Wrong Answer
time: 660ms
memory: 112456kb

input:

1000
83 90
2 71 72
2 6 16
2 78 3
2 24 25
2 39 65
2 19 9
2 10 14
1 30
2 86 65
2 17 18
1 47
2 69 68
1 7
2 64 7
2 31 68
2 90 89
2 85 4
2 22 79
2 12 62
2 56 66
1 83
1 88
2 43 45
2 50 20
2 15 14
2 38 59
1 32
1 80
2 33 6
1 61
2 15 41
2 47 20
2 78 52
2 1 13
1 18
2 6 63
2 70 62
2 25 27
1 74
2 8 2
2 65 41
2 ...

output:

19
13
12
14
22
17
15
14
12
12
12
11
16
18
16
12
13
13
16
13
12
18
9
16
12
8
12
11
19
17
24
11
18
14
19
9
15
21
14
17
-1
16
-1
9
8
21
-1
13
15
13
18
19
20
15
13
12
18
14
12
15
14
-1
12
17
13
-1
19
11
18
9
9
13
-1
-1
-1
10
21
19
12
11
12
13
11
20
17
10
8
10
12
13
14
16
13
17
17
18
-1
-1
11
10
16
14
17...

result:

wrong answer 1st numbers differ - expected: '37', found: '19'

Test #25:

score: 0
Wrong Answer
time: 637ms
memory: 110180kb

input:

1000
80 90
2 66 52
2 74 17
2 42 71
2 59 58
2 86 21
1 81
2 25 63
1 52
1 1
1 25
2 2 22
1 89
1 39
1 28
2 78 85
2 67 76
1 85
2 30 31
2 12 13
2 25 38
1 33
2 38 71
1 9
2 62 61
1 16
1 54
2 52 66
2 5 15
2 14 13
2 69 3
2 70 66
2 37 25
2 21 27
2 34 6
2 44 85
2 12 33
1 75
2 51 53
2 4 45
2 39 82
1 26
1 15
2 46 ...

output:

23
17
13
11
12
-1
17
16
12
13
11
21
14
14
15
23
8
15
16
18
12
17
18
11
-1
12
10
14
20
-1
12
11
23
17
14
17
19
12
16
18
15
-1
16
9
14
12
11
13
15
18
15
20
19
17
17
20
20
20
14
-1
11
17
13
16
18
-1
17
14
8
19
-1
14
11
17
-1
-1
13
14
13
15
13
19
16
20
9
14
23
18
14
11
26
12
23
12
18
9
15
19
12
67
14
18...

result:

wrong answer 1st numbers differ - expected: '38', found: '23'