QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#563629#9260. Raiffeisenbank LogisticsPhantomThreshold#TL 753ms4132kbC++202.6kb2024-09-14 14:33:062024-09-14 14:33:07

Judging History

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

  • [2024-09-14 14:33:07]
  • 评测
  • 测评结果:TL
  • 用时:753ms
  • 内存:4132kb
  • [2024-09-14 14:33:06]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxn = 1510000;

int n,m;
int tot;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int Tcase; cin>>Tcase;
    while(Tcase--)
    {
        vector< vector< pair<int,int> > >E;
        vector< vector<int> >V;
        vector< tuple<int,int,int> >ei;

        cin>>n>>m;
        V.resize(n+5);
        for(int i=1;i<=m;i++)
        {
            int x,y,t; cin>>x>>y>>t;
            ei.emplace_back(x,y,t);
            V[x].push_back(t),V[y].push_back(t);
            V[x].push_back(t+1),V[y].push_back(t+1);
        }
        
        if(V[1].empty())
        {
            cout<<-1<<'\n';
            continue;
        }

        tot=0;
        map< pair<int,int>,int>mp;
        for(int i=1;i<=n;i++)
        {
            sort(V[i].begin(),V[i].end());
            for(auto t:V[i])
            {
                auto temp= make_pair(i,t);
                if(mp.count(temp)==0) 
                {
                    mp[temp]=++tot;
            //        cerr<<i<<' '<<t<<' '<<tot<<endl;
                }
            }
        }
        E.resize(tot+5);
        for(int i=1;i<=n;i++)
        {
            int las=-1;
            for(auto t:V[i])
            {
                if(las!=-1 && las!=t)
                {
                    int u= mp[make_pair(i,las)], v=mp[make_pair(i,t)];
                    E[u].emplace_back(0,v);
                }
                las=t;
            }
        }
        for(auto [x,y,t]:ei)
        {
            E[ mp[make_pair(x,t)] ].emplace_back(0, mp[make_pair(y,t+1)] );
            E[ mp[make_pair(y,t)] ].emplace_back(1, mp[make_pair(x,t+1)] );
        }
        
        const int inf = 1e9;
        vector<int>dis(tot+5);
        for(int i=1;i<=tot;i++) dis[i]=inf;
        deque< pair<int,int> >q;
        dis[1]=0; q.push_back( make_pair(1,0) );
        while(!q.empty())
        {
            const auto [x,dx]=q.front(); q.pop_front();
            if(dx!=dis[x]) continue;
            for(auto [c,y]:E[x])
            {
                if(dis[y]>dx+c)
                {
                    dis[y]=dx+c;
                    if( c==0 ) q.push_front( make_pair(y,dis[y]) );
                    else q.push_back( make_pair(y,dis[y]) );
                }
            }
        }
        int ans=inf;
        for(auto t:V[n])
        {
            int u= mp[make_pair(n,t)];
            ans=min(ans,dis[u]);
        }
        if(ans==inf) ans=-1;
        cout<<ans<<'\n';
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
4 3
2 1 1
2 3 2
4 3 3

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

2
4 3
2 1 1
2 3 2
4 3 2
8 9
1 2 5
2 3 10
4 3 15
4 5 20
5 8 25
1 6 2
6 5 30
7 6 3
8 7 4

output:

-1
1

result:

ok 2 number(s): "-1 1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

8
2 1
1 2 1
2 1
2 1 1
2 1
1 1 1
2 1
2 2 1
2 1
1 2 1000000000
2 1
2 1 1000000000
2 1
1 1 1000000000
2 1
2 2 1000000000

output:

0
1
-1
-1
0
1
-1
-1

result:

ok 8 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

1
2 1
1 2 1

output:

0

result:

ok 1 number(s): "0"

Test #5:

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

input:

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

result:

ok 1000 numbers

Test #7:

score: 0
Accepted
time: 7ms
memory: 3648kb

input:

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

output:

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

result:

ok 1000 numbers

Test #8:

score: 0
Accepted
time: 8ms
memory: 3584kb

input:

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

output:

2
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
1
2
-1
0
-1
-1
-1
-1
0
2
-1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
-1
-1
-1
-1
-1
0
-1
0
-1
-1
-1
-1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
-1
-1
-1
0
2
-1
-1
-1
3
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
-1
-1
...

result:

ok 1000 numbers

Test #9:

score: 0
Accepted
time: 9ms
memory: 3872kb

input:

1000
10 10
5 3 21
1 6 60
3 10 31
7 9 51
10 7 64
5 6 85
3 4 85
5 1 7
5 3 52
1 7 17
10 10
1 1 90
2 9 78
9 2 82
9 9 29
2 7 67
8 8 44
7 9 87
8 3 3
9 5 32
5 8 15
10 10
2 8 22
3 2 97
7 7 34
1 6 43
5 9 24
4 7 35
3 3 48
9 4 33
5 10 93
1 7 65
10 10
5 4 85
5 1 40
8 9 48
7 1 57
10 10 69
2 2 69
6 4 14
8 4 43
10...

output:

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

result:

ok 1000 numbers

Test #10:

score: 0
Accepted
time: 9ms
memory: 3596kb

input:

1000
10 10
10 10 268155137
5 10 540061009
1 10 110627680
1 4 533692575
3 5 10438095
6 7 730490278
6 2 985939776
8 10 500039201
1 9 185735931
4 2 729538420
10 10
8 1 326383784
5 3 726281100
4 6 279162422
4 4 243297959
1 2 984988531
3 10 856724546
2 4 627158366
4 5 880246199
9 1 675003875
7 7 76366643...

output:

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

result:

ok 1000 numbers

Test #11:

score: 0
Accepted
time: 8ms
memory: 3640kb

input:

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

output:

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

result:

ok 1000 numbers

Test #12:

score: 0
Accepted
time: 11ms
memory: 3540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
2
-1
0
1
1
-1
-1
-1
-1
-1
0
1
1
-1
-1
2
-1
-1
2
2
0
1
-1
0
-1
-1
0
1
-1
1
-1
0
-1
-1
0
1
2
0
0
-1
1
-1
1
0
-1
-1
-1
-1
0
0
-1
-1
0
2
1
0
1
-1
-1
2
1
1
0
0
2
2
1
1
-1
0
0
0
1
0
-1
1
-1
1
0
0
-1
-1
-1
-1
1
-1
-1...

result:

ok 1000 numbers

Test #14:

score: 0
Accepted
time: 20ms
memory: 3656kb

input:

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

output:

-1
-1
1
-1
0
0
-1
-1
0
0
-1
0
0
1
1
2
-1
1
2
0
-1
-1
-1
0
1
-1
-1
-1
-1
-1
1
0
-1
1
0
0
0
1
0
-1
-1
0
0
-1
1
1
1
1
-1
-1
1
0
0
-1
-1
0
1
-1
1
1
1
1
0
1
1
0
1
1
-1
-1
2
-1
0
1
-1
0
2
-1
0
1
0
0
-1
-1
-1
1
1
-1
-1
0
-1
1
1
-1
-1
1
-1
2
1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
-1
0
-1
0
-1
-1
0
-1
-1
3...

result:

ok 1000 numbers

Test #15:

score: 0
Accepted
time: 19ms
memory: 3580kb

input:

1000
10 20
2 4 98
7 8 21
7 1 36
6 1 61
4 2 77
1 3 60
5 4 6
6 6 9
4 4 7
7 10 76
4 6 49
6 3 44
3 10 23
9 4 12
7 5 15
2 1 7
3 3 83
4 7 79
8 1 93
10 6 96
10 20
5 5 31
3 8 37
8 8 59
1 8 33
1 9 94
7 7 73
1 9 24
10 3 97
9 5 36
3 1 73
6 3 46
4 2 83
4 4 98
7 7 96
5 10 60
5 2 76
5 2 61
6 4 29
1 10 99
6 3 92
1...

output:

1
0
-1
-1
0
0
-1
1
1
0
0
-1
1
0
0
0
0
1
0
1
-1
0
0
-1
-1
-1
-1
0
1
0
0
1
-1
0
1
-1
-1
1
1
1
2
1
0
-1
-1
0
1
1
1
1
-1
2
0
1
-1
1
1
0
-1
-1
0
-1
0
0
0
1
-1
1
-1
-1
-1
1
0
-1
2
1
-1
1
-1
-1
1
0
-1
1
0
0
-1
0
1
0
1
0
-1
0
0
0
0
1
0
-1
0
0
0
1
2
0
0
1
-1
1
2
0
0
1
-1
1
3
0
-1
0
0
1
0
0
-1
0
1
1
1
1
-1
-1...

result:

ok 1000 numbers

Test #16:

score: 0
Accepted
time: 23ms
memory: 3660kb

input:

1000
10 20
9 8 326353980
1 10 321178299
4 8 970616710
4 9 550923176
8 9 682488932
10 6 752852755
5 10 399703822
10 10 207683413
7 9 84451826
7 8 820433227
7 5 97884128
6 7 1405220
1 5 287655030
8 9 868446569
4 1 421832399
9 4 913601101
2 9 361785960
9 3 425625400
3 9 1891923
8 1 112588430
10 20
6 9 ...

output:

0
-1
0
1
-1
-1
-1
-1
0
-1
1
1
0
2
0
1
0
1
1
-1
-1
2
-1
0
0
1
-1
1
0
2
-1
1
1
1
1
0
0
-1
0
-1
0
0
1
1
1
0
2
-1
2
1
-1
0
0
-1
0
2
3
-1
-1
2
1
0
0
1
3
0
1
1
-1
-1
0
0
-1
1
0
1
1
1
1
0
1
0
1
1
3
0
-1
0
1
-1
-1
1
-1
-1
0
1
1
1
0
-1
0
0
-1
0
1
1
2
1
0
1
0
0
0
0
0
0
-1
-1
-1
-1
-1
1
1
-1
-1
0
1
0
1
-1
2
1
...

result:

ok 1000 numbers

Test #17:

score: 0
Accepted
time: 16ms
memory: 3660kb

input:

1000
10 50
10 1 1
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1
0
0
0
0
1
0
0
1
1
1
2
0
0
0
0
0
0
0
0
1
1
1
0
0
0
0
2
1
1
1
0
0
0
1
1
1
1
0
0
1
0
0
1
1
1
1
0
0
1
1
1
1
0
1
0
0
1
-1
0
0
1
1
0
0
0
1
1
0
-1
0
0
0
-1
0
0
2
0
-1
0
0
0
1
0
0
0
0
1
0
-1
0
1
0
0
0
1
...

result:

ok 1000 numbers

Test #19:

score: 0
Accepted
time: 27ms
memory: 3564kb

input:

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

output:

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

result:

ok 1000 numbers

Test #20:

score: 0
Accepted
time: 44ms
memory: 3884kb

input:

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

output:

1
0
0
0
1
0
0
0
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
1
0
0
0
0
0
0
0
1
0
0
0
0
0
1
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
...

result:

ok 1000 numbers

Test #21:

score: 0
Accepted
time: 63ms
memory: 3728kb

input:

1000
10 50
6 5 76
2 8 63
7 8 83
4 9 100
7 3 28
7 7 60
10 7 8
10 1 49
8 4 16
3 5 51
6 9 84
6 1 43
7 7 36
9 4 97
7 2 39
4 10 41
3 6 68
4 3 1
7 8 53
4 2 74
8 5 5
3 7 63
3 5 38
6 7 25
5 9 83
7 3 85
1 5 72
5 2 15
5 1 51
7 8 56
7 5 13
1 7 98
1 1 17
3 3 26
3 3 19
1 9 10
5 4 17
10 10 56
3 1 90
1 10 42
3 1 2...

output:

0
1
0
0
0
1
0
0
0
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
0
0
1
0
1
0
0
1
0
0
0
1
0
0
0
1
1
0
0
0
0
0
1
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
1
0
1
0
0
0
0
1
0
0
0
0
1
0
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
1
0
0
1
0
1
0
0
0
0
1
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 numbers

Test #22:

score: 0
Accepted
time: 65ms
memory: 3908kb

input:

1000
10 50
2 2 954153759
1 3 283444488
8 10 897162377
6 2 701352810
5 8 872948443
6 10 320895294
10 9 697730752
5 4 375661090
3 4 673334850
6 9 215515206
10 7 977251708
6 1 888046403
5 2 292147356
9 9 840382008
3 10 430429980
6 8 921004331
4 10 298467905
7 1 160104863
10 3 444341972
10 4 653051505
9...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
1
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
1
0
0
1
0
0
1
0
0
0
0
0
0
0
0
1
0
1
0
0
1
0
1
0
0
0
0
1
0
0
0
1
0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
1
1
1
0
0
1
...

result:

ok 1000 numbers

Test #23:

score: 0
Accepted
time: 101ms
memory: 3612kb

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 numbers

Test #24:

score: 0
Accepted
time: 130ms
memory: 3880kb

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 numbers

Test #25:

score: 0
Accepted
time: 148ms
memory: 3640kb

input:

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

result:

ok 1000 numbers

Test #27:

score: 0
Accepted
time: 530ms
memory: 3804kb

input:

1000
10 500
4 6 30
2 6 44
4 4 52
5 3 43
7 4 18
1 9 46
3 7 9
3 6 83
9 6 58
3 6 58
9 8 100
10 7 62
3 5 64
5 5 53
6 8 95
1 6 12
1 1 72
10 9 93
4 2 82
8 8 73
4 8 32
9 3 92
5 2 75
4 1 92
10 2 83
10 3 57
9 10 13
3 7 37
6 1 100
9 3 12
7 3 67
6 6 14
4 8 86
8 2 4
4 3 8
7 6 15
10 8 56
6 8 98
4 5 30
7 7 36
1 6...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 numbers

Test #28:

score: 0
Accepted
time: 753ms
memory: 4132kb

input:

1000
10 500
8 9 67526824
5 4 559064935
10 5 4911091
10 1 665435421
10 9 676899734
7 1 937378183
8 5 573246092
4 7 989380774
4 6 200810178
7 1 416005093
8 8 742684190
1 10 268750539
2 5 718281171
1 8 934536165
1 5 814664163
2 7 237449715
2 1 203051765
6 7 306356562
10 3 428234841
3 1 760994730
10 2 7...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 numbers

Test #29:

score: 0
Accepted
time: 376ms
memory: 3760kb

input:

1000
500 500
363 349 1
362 206 1
163 390 1
137 172 1
302 114 1
71 291 1
174 386 1
290 118 1
455 251 1
221 39 1
349 64 1
496 62 1
385 170 1
391 24 1
266 372 1
86 223 1
3 209 1
336 410 1
408 288 1
19 470 1
110 356 1
66 95 1
156 271 1
220 405 1
348 367 1
188 485 1
1 499 1
148 160 1
273 394 1
227 401 1
...

output:

-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
-...

result:

ok 1000 numbers

Test #30:

score: 0
Accepted
time: 441ms
memory: 3764kb

input:

1000
500 500
268 243 2
164 390 1
155 185 1
45 113 1
214 25 1
469 95 2
263 38 1
59 179 2
353 494 2
203 171 1
240 167 2
135 496 1
252 77 2
35 403 1
86 257 1
38 370 1
341 328 1
226 268 1
284 321 1
143 8 1
317 179 2
120 124 1
265 78 2
447 80 2
336 14 1
154 249 1
227 90 2
137 390 1
227 186 1
345 108 1
26...

output:

-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
...

result:

ok 1000 numbers

Test #31:

score: 0
Accepted
time: 468ms
memory: 3796kb

input:

1000
500 500
421 241 2
100 61 2
388 163 1
422 52 1
488 175 2
272 57 1
392 97 2
265 460 2
140 292 3
29 58 1
364 328 3
139 231 3
354 453 1
45 484 1
197 423 1
9 257 2
275 359 2
22 160 1
279 54 1
197 206 3
268 384 2
85 308 1
372 164 2
340 282 1
348 130 2
67 448 2
66 452 2
79 418 3
332 388 3
217 369 2
12...

output:

-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
...

result:

ok 1000 numbers

Test #32:

score: 0
Accepted
time: 508ms
memory: 3808kb

input:

1000
500 500
143 491 2
362 354 3
485 14 4
325 343 1
209 342 1
192 472 3
295 6 1
178 387 4
246 328 1
131 314 1
81 453 2
405 283 3
351 348 1
178 256 4
463 405 4
181 32 2
408 249 3
488 292 4
4 288 1
48 206 2
215 17 1
14 464 3
463 135 4
10 40 4
78 357 4
234 367 4
467 455 4
357 355 2
424 214 2
88 353 2
3...

output:

-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...

result:

ok 1000 numbers

Test #33:

score: 0
Accepted
time: 522ms
memory: 3888kb

input:

1000
500 500
140 313 3
155 280 5
197 292 4
234 230 2
348 46 2
269 194 5
434 202 4
33 311 3
152 335 1
384 145 3
235 127 4
370 147 2
444 328 1
127 2 3
357 189 4
255 141 5
460 386 2
398 138 5
326 417 3
51 108 1
22 33 4
251 390 2
79 74 1
215 245 1
482 366 1
253 449 1
460 25 4
318 157 4
380 336 2
225 356...

output:

-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
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

ok 1000 numbers

Test #34:

score: -100
Time Limit Exceeded

input:

5
10000 100000
16 3559 468695643
7133 1854 827377604
2253 8986 212718926
3378 8735 205907497
3784 3272 98819139
5961 1839 898392689
4722 371 109250145
8884 4871 589883888
7498 9813 70864069
9475 6017 175126069
2932 4557 863780576
7285 6064 122334857
5448 5260 360605203
2995 6162 705458859
9806 2832 ...

output:

1
0
2
0
0

result: