QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#853040#9735. Japanese Bandsucup-team112#AC ✓1156ms93576kbC++2314.9kb2025-01-11 15:24:292025-01-11 15:24:29

Judging History

你现在查看的是测评时间为 2025-01-11 15:24:29 的历史记录

  • [2025-01-18 23:48:47]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:1216ms
  • 内存:93656kb
  • [2025-01-18 23:34:05]
  • hack成功,自动添加数据
  • (/hack/1459)
  • [2025-01-11 15:24:29]
  • 评测
  • 测评结果:100
  • 用时:1156ms
  • 内存:93576kb
  • [2025-01-11 15:24:29]
  • 提交

answer


//#define _GLIBCXX_DEBUG

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

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


#ifdef LOCAL
#include <debug_print.hpp>
#define OUT(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define OUT(...) (static_cast<void>(0))
#endif

#define endl '\n'
#define lfs cout<<fixed<<setprecision(15)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)

namespace template_tute{
  using ll = long long;
  using ld = long double;
  const ll MOD1 = 1e9+7;
  const ll MOD9 = 998244353;
  const ll INF = 4.1e18;
  using P = pair<ll, ll>;
  template<typename T> using PQ = priority_queue<T>;
  template<typename T> using QP = priority_queue<T,vector<T>,greater<T>>;
  template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
  template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
  ll median(ll a,ll b, ll c){return a+b+c-max<ll>({a,b,c})-min<ll>({a,b,c});}
  void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
  void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
  void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
  template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
  template<typename T1,typename T2,typename T3>void anss(T1 x,T2 y,T3 z){ans(x!=y,x,z);};  
  template<typename T>void debug(const T &v,ll h,ll w,string sv=" "){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout<<sv<<v[i][j];cout<<endl;}};
  template<typename T>void debug(const T &v,ll n,string sv=" "){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout<<sv<<v[i];cout<<endl;};
  template<typename T>void debug(const vector<T>&v){debug(v,v.size());}
  template<typename T>void debug(const vector<vector<T>>&v){for(auto &vv:v)debug(vv,vv.size());}
  template<typename T>void debug(stack<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
  template<typename T>void debug(queue<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop();}cout<<endl;}
  template<typename T>void debug(deque<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop_front();}cout<<endl;}
  template<typename T>void debug(PQ<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
  template<typename T>void debug(QP<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
  template<typename T>void debug(const set<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
  template<typename T>void debug(const multiset<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
  template<typename T,size_t size>void debug(const array<T, size> &a){for(auto z:a)cout<<z<<" ";cout<<endl;}
  template<typename T,typename V>void debug(const map<T,V>&v){for(auto z:v)cout<<"["<<z.first<<"]="<<z.second<<",";cout<<endl;}
  template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
  vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
  template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
  template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
  template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << "(" << p.first << "," << p.second << ")";}
  template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){os<<"[";for(auto &z:v)os << z << ",";os<<"]"; return os;}
  template<typename T>void rearrange(vector<int>&ord, vector<T>&v){
    auto tmp = v;
    for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
  }
  template<typename Head, typename... Tail>void rearrange(vector<int>&ord,Head&& head, Tail&&... tail){
    rearrange(ord, head);
    rearrange(ord, tail...);
  }
  template<typename T> vector<int> ascend(const vector<T>&v){
    vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
    sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],i)<make_pair(v[j],j);});
    return ord;
  }
  template<typename T> vector<int> descend(const vector<T>&v){
    vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
    sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],-i)>make_pair(v[j],-j);});
    return ord;
  }
  template<typename T> vector<T> inv_perm(const vector<T>&ord){
    vector<T>inv(ord.size());
    for(int i=0;i<ord.size();i++)inv[ord[i]] = i;
    return inv;
  }
  ll FLOOR(ll n,ll div){assert(div>0);return n>=0?n/div:(n-div+1)/div;}
  ll CEIL(ll n,ll div){assert(div>0);return n>=0?(n+div-1)/div:n/div;}
  ll digitsum(ll n){ll ret=0;while(n){ret+=n%10;n/=10;}return ret;}
  ll modulo(ll n,ll d){return (n%d+d)%d;};
  template<typename T>T min(const vector<T>&v){return *min_element(v.begin(),v.end());}
  template<typename T>T max(const vector<T>&v){return *max_element(v.begin(),v.end());}
  template<typename T>T acc(const vector<T>&v){return accumulate(v.begin(),v.end(),T(0));};
  template<typename T>T reverse(const T &v){return T(v.rbegin(),v.rend());};
  //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
  int popcount(ll x){return __builtin_popcountll(x);};
  int poplow(ll x){return __builtin_ctzll(x);};
  int pophigh(ll x){return 63 - __builtin_clzll(x);};
  template<typename T>T poll(queue<T> &q){auto ret=q.front();q.pop();return ret;};
  template<typename T>T poll(priority_queue<T> &q){auto ret=q.top();q.pop();return ret;};
  template<typename T>T poll(QP<T> &q){auto ret=q.top();q.pop();return ret;};
  template<typename T>T poll(stack<T> &s){auto ret=s.top();s.pop();return ret;};
  ll MULT(ll x,ll y){if(LLONG_MAX/x<=y)return LLONG_MAX;return x*y;}
  ll POW2(ll x, ll k){ll ret=1,mul=x;while(k){if(mul==LLONG_MAX)return LLONG_MAX;if(k&1)ret=MULT(ret,mul);mul=MULT(mul,mul);k>>=1;}return ret;}
  ll POW(ll x, ll k){ll ret=1;for(int i=0;i<k;i++){if(LLONG_MAX/x<=ret)return LLONG_MAX;ret*=x;}return ret;}
  std::ostream &operator<<(std::ostream &dest, __int128_t value) {
    std::ostream::sentry s(dest);
    if (s) {
      __uint128_t tmp = value < 0 ? -value : value;
      char buffer[128];
      char *d = std::end(buffer);
      do {
        --d;
        *d = "0123456789"[tmp % 10];
        tmp /= 10;
      } while (tmp != 0);
      if (value < 0) {
        --d;
        *d = '-';
      }
      int len = std::end(buffer) - d;
      if (dest.rdbuf()->sputn(d, len) != len) {
        dest.setstate(std::ios_base::badbit);
      }
    }
    return dest;
  }
  namespace converter{
    int dict[500];
    const string lower="abcdefghijklmnopqrstuvwxyz";
    const string upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    const string digit="0123456789";
    const string digit1="123456789";
    void regi_str(const string &t){
      for(int i=0;i<t.size();i++){
        dict[t[i]]=i;
      }
    }
    void regi_int(const string &t){
      for(int i=0;i<t.size();i++){
        dict[i]=t[i];
      }
    }
    vector<int>to_int(const string &s,const string &t){
      regi_str(t);
      vector<int>ret(s.size());
      for(int i=0;i<s.size();i++){
        ret[i]=dict[s[i]];
      }
      return ret;
    }
    vector<int>to_int(const string &s){
      auto t=s;
      sort(t.begin(),t.end());
      t.erase(unique(t.begin(),t.end()),t.end());
      return to_int(s,t);
    }
    
    vector<vector<int>>to_int(const vector<string>&s,const string &t){
      regi_str(t);
      vector<vector<int>>ret(s.size(),vector<int>(s[0].size()));
      for(int i=0;i<s.size();i++){
        for(int j=0;j<s[0].size();j++){
          ret[i][j]=dict[s[i][j]];
        }
      }
      return ret;
    }
    vector<vector<int>>to_int(const vector<string>&s){
      string t;
      for(int i=0;i<s.size();i++){
        t+=s[i];
      }
      sort(t.begin(),t.end());t.erase(unique(t.begin(),t.end()),t.end());
      return to_int(s,t);
    }
    string to_str(const vector<int>&s,const string &t){
      regi_int(t);
      string ret;
      for(auto z:s)ret+=dict[z];
      return ret;
    }
    vector<string> to_str(const vector<vector<int>>&s,const string &t){
      regi_int(t);
      vector<string>ret(s.size());
      for(int i=0;i<s.size();i++){
        for(auto z:s[i])ret[i]+=dict[z];
      }
      return ret;
    }
  }
  template< typename T = int >
  struct edge {
    int to;
    T cost;
    int id;
    edge():to(-1),id(-1){};
    edge(int to, T cost = 1, int id = -1):to(to), cost(cost), id(id){}
    operator int() const { return to; }
  };

  template<typename T>
  using Graph = vector<vector<edge<T>>>;
  template<typename T>
  Graph<T>revgraph(const Graph<T> &g){
    Graph<T>ret(g.size());
    for(int i=0;i<g.size();i++){
      for(auto e:g[i]){
        int to = e.to;
        e.to = i;
        ret[to].push_back(e);
      }
    }
    return ret;
  }
  template<typename T>
  Graph<T> readGraph(int n,int m,int indexed=1,bool directed=false,bool weighted=false){
    Graph<T> ret(n);
    for(int es = 0; es < m; es++){
      int u,v;
      T w=1;
      cin>>u>>v;u-=indexed,v-=indexed;
      if(weighted)cin>>w;
      ret[u].emplace_back(v,w,es);
      if(!directed)ret[v].emplace_back(u,w,es);
    }
    return ret;
  }
  template<typename T>
  Graph<T> readParent(int n,int indexed=1,bool directed=true){
    Graph<T>ret(n);
    for(int i=1;i<n;i++){
      int p;cin>>p;
      p-=indexed;
      ret[p].emplace_back(i);
      if(!directed)ret[i].emplace_back(p);
    }
    return ret;
  }
}
using namespace template_tute;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  friend ModInt operator+(const ModInt& lhs, const ModInt& rhs) {
        return ModInt(lhs) += rhs;
  }
  friend ModInt operator-(const ModInt& lhs, const ModInt& rhs) {
        return ModInt(lhs) -= rhs;
  }
  friend ModInt operator*(const ModInt& lhs, const ModInt& rhs) {
        return ModInt(lhs) *= rhs;
  }
  friend ModInt operator/(const ModInt& lhs, const ModInt& rhs) {
        return ModInt(lhs) /= rhs;
  }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  pair<int,int>frac(){
    for(int j=1;j<=10000;j++){
      auto v=*this*j;
      if(v.x<=10000)return make_pair(v.x,j);
      else if(v.x>=mod-10000)return make_pair(-(v.x-mod),j);
    }
    return make_pair(-1,-1);
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static constexpr int get_mod() { return mod; }
};

template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;

  Combination(ll sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(ll i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(ll i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(ll i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }

  inline T fact(ll k) const { return _fact[k]; }

  inline T rfact(ll k) const { return _rfact[k]; }

  inline T inv(ll k) const { return _inv[k]; }

  T P(ll n, ll r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  T C(ll p, ll q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }

  T RC(ll p, ll q) const {
    if(q < 0 || p < q) return 0;
    return rfact(p) * fact(q) * fact(p - q);
  }

  T H(ll n, ll r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
  //+1がm個、-1がn個で prefix sumが常にk以上
  T catalan(ll m,ll n,ll k){
    if(n>m-k)return 0;
    else return C(n+m,m)-C(n+m,n+k-1);
  }
};
using modint = ModInt< MOD1 >;modint mpow(ll n, ll x){return modint(n).pow(x);}modint mpow(modint n, ll x){return n.pow(x);}
//using modint=ld;modint mpow(ll n, ll x){return pow(n,x);}modint mpow(modint n, ll x){return pow(n,x);}
using Comb=Combination<modint>;


void solve(){
	ll res=0,buf=0;
  bool judge = true;

  ll n1,n2;cin>>n1>>n2;
  ll m,k;cin>>m>>k;
  vector<ll>adj(m);
  rep(i,0,k){
    ll a,b;cin>>a>>b;a--;b--;
    adj[a]|=1<<b;
    adj[b]|=1<<a;
  }
  vector<modint>c1(m+1),c2(m+1);
  auto calced=[&](ll n,ll c)->modint {
    //特定のc種類からn個
    //cH(n-c)=(n-1)C(c-1)
    if(c==0)return 0;
    modint ret=1;
    rep(i,0,c-1){
      ret*=(n-1-i);
      ret/=i+1;
    }
    return ret;
  };
  rep(i,0,m+1){
    c1[i]=calced(n1,i);
    c2[i]=calced(n2,i);
  };
  using A=array<modint,21>;
  vector<A>dp(1<<m,{0});
  dp[0][0]=1;
  rep(i,1,1<<m){
    ll h=pophigh(i);
    bool ch=adj[h]>>h&1;
    ll rem=(i^(1<<h))&(~adj[h]);
    ll cnt=popcount(adj[h]&(i^(1<<h)));
    if(!ch){
      rep(j,0,m+1){
        if(cnt+j<=m){
          dp[i][cnt+j]+=dp[rem][j];
        }
      }
    }
    rep(j,0,m){
      dp[i][j+1]+=dp[i^(1<<h)][j];
    }
  }
  vector<modint>mult(1<<m);
  //OUT(c1,c2);
  rep(i,0,1<<m){
    ll pct=popcount(i);
    rep(j,0,m+1){
      if(dp[i][j]==0)continue;
      mult[i]+=dp[i][j]*c2[j+m-pct];
    }
    //OUT(i,mult[i],dp[i]);
  }
  modint ret=0;
  rep(i,1,1<<m){
    modint add=c1[popcount(i)];
    ll bit=0;
    rep(j,0,m){
      if(~i>>j&1){
        if((adj[j]&i)!=adj[j]){
          add=0;
        }
        if(adj[j]>0){
          bit|=1<<j;
        }
      }
    }
    ret+=add*mult[bit^((1<<m)-1)];
  }
  cout<<ret<<endl;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  int T = 1;
  cin>>T;
  while(T--){
    solve();
  }
  return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3908kb

input:

3
2 3 3 3
2 3
1 1
2 3
2 2 2 1
1 1
1 1 10 2
1 2
1 3

output:

6
4
0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1084ms
memory: 93576kb

input:

500
481199252 336470888 8 58
4 7
7 6
4 7
2 6
2 6
2 7
8 3
8 7
8 1
2 6
2 6
1 2
1 5
3 1
6 4
2 4
4 7
2 6
2 3
7 1
4 4
5 1
2 7
6 7
8 1
8 7
5 6
4 2
4 2
8 5
5 4
6 8
5 6
3 8
1 7
1 6
7 1
5 6
6 3
1 1
2 7
3 3
1 5
5 5
8 7
3 4
6 3
8 8
7 4
1 6
2 1
8 7
4 5
2 7
3 5
2 6
4 5
4 3
2 6 2 2
2 1
1 1
500330171 987581927 10 ...

output:

724920553
11
966099120
846759476
528107862
1
245313614
144990327
1
269113412
946380890
1
0
996348464
376698469
453289929
53346774
238565800
260837053
956196844
0
487514263
842710229
8376584
16
300260118
933415828
808801372
1
612901047
137099259
14974173
0
531418108
1
522718622
264859767
1
1
59318545...

result:

ok 500 lines

Test #3:

score: 0
Accepted
time: 1057ms
memory: 93512kb

input:

500
54748096 75475634 8 64
3 8
3 2
3 5
5 6
5 7
5 4
2 2
5 8
5 3
3 5
7 6
1 7
3 3
6 8
3 5
3 4
1 2
7 5
7 6
4 7
8 7
7 5
4 2
3 2
8 5
7 1
4 3
4 6
3 3
8 3
6 1
5 4
1 4
2 3
5 6
1 4
5 8
8 2
1 3
8 1
5 7
1 2
3 8
4 2
5 4
7 2
4 6
5 8
4 6
3 5
5 7
4 6
4 8
6 4
7 4
3 3
5 2
1 6
4 5
3 1
1 4
5 6
4 3
3 1
44007561 94403501...

output:

48662676
1
138912221
349671067
150052712
86775188
956490545
756234965
1
567881550
726030753
1
914856825
867349578
0
784807018
388018114
433007753
524010032
507842496
282218203
442034917
668340856
1
1
1
489645337
153477090
564466420
1673
0
390234222
604892803
264163973
601602052
135055881
27720
15744...

result:

ok 500 lines

Test #4:

score: 0
Accepted
time: 1064ms
memory: 93512kb

input:

500
923264237 374288891 9 36
8 8
5 8
3 6
2 4
2 6
4 7
3 8
3 4
5 5
5 1
9 3
1 9
5 4
5 8
4 3
2 8
7 6
7 3
8 9
3 4
4 1
8 1
7 3
6 3
6 2
9 6
2 3
2 5
6 1
8 5
4 5
3 1
8 7
6 5
3 2
1 1
885955146 964950238 8 59
1 3
7 7
8 1
2 7
6 5
1 3
1 2
2 3
1 2
8 2
4 1
5 6
5 8
3 1
8 3
2 3
8 3
6 5
2 5
6 7
7 2
6 3
6 5
6 7
7 8
8 ...

output:

975815187
715739872
849684680
940532257
1
181582862
672614348
487379998
1
872849956
969457677
827780523
98088
1
496360790
568133531
231661973
1
981238143
13510
8
663802864
252
107191472
18522
415132978
697199493
116414735
1
10
912343690
81
583097677
223080594
33251656
117275734
1
419400938
630591794...

result:

ok 500 lines

Test #5:

score: 0
Accepted
time: 1127ms
memory: 93472kb

input:

500
1 9 7 21
4 3
4 5
4 3
4 5
4 5
4 7
4 7
4 2
4 3
4 6
4 1
4 7
4 5
4 1
4 2
4 2
4 2
4 1
4 2
4 6
4 6
192019400 315755530 10 56
8 10
9 7
9 6
8 4
3 4
1 6
8 7
9 10
8 7
5 7
2 4
5 7
1 6
9 7
2 4
1 4
2 7
5 7
5 7
2 10
3 7
8 4
8 4
3 4
5 7
9 6
2 10
3 4
8 10
9 4
5 10
2 4
8 7
5 4
5 7
9 4
8 6
1 7
5 4
8 10
3 4
9 7
8 ...

output:

84
668356110
663215632
0
0
578736401
597267922
0
33363799
1161
80106560
13486
379410136
346687579
215079152
954964869
0
749122504
842423167
0
739926379
822901144
642136628
770357778
886
370384128
817027991
684214806
463554366
759552089
16
384293072
744192004
475
443091214
298039661
815658191
7064088...

result:

ok 500 lines

Test #6:

score: 0
Accepted
time: 1133ms
memory: 93424kb

input:

500
365329221 412106895 9 25
3 8
3 9
3 6
3 4
3 4
3 5
3 2
3 9
3 4
3 8
3 7
3 7
3 4
3 7
3 5
3 4
3 1
3 6
3 2
3 2
3 1
3 2
3 7
3 2
3 9
777109873 324284579 2 4
2 1
2 1
2 1
2 1
203265013 578140767 9 46
4 7
4 3
4 9
4 8
4 6
4 9
4 8
4 3
4 6
4 9
4 1
4 6
4 2
4 1
4 3
4 2
4 2
4 9
4 2
4 8
4 1
4 1
4 3
4 2
4 6
4 2
4 ...

output:

437314267
339909689
523663972
939772260
15
294996
873351127
420170527
361605716
10
6317
1015
698532307
716316221
827134829
526287544
433650509
256800385
596882660
574424501
589351733
505841163
517919676
378556809
150786280
1
4103867
986751324
345294966
926479261
557962762
987
133774068
568046845
778...

result:

ok 500 lines

Test #7:

score: 0
Accepted
time: 1123ms
memory: 93516kb

input:

500
643910770 5887448 4 3
2 3
4 3
2 3
483024012 714786389 2 1
2 1
735205996 288464482 7 46
4 2
3 7
5 7
4 2
3 1
5 2
4 2
5 2
3 6
3 6
3 2
3 2
3 2
5 7
5 7
4 7
5 2
5 1
4 6
4 1
5 7
5 6
3 2
4 2
3 1
5 7
3 2
4 7
4 2
3 7
3 2
5 7
4 1
3 1
3 1
5 2
5 2
5 6
4 1
4 1
4 2
4 7
4 2
5 1
3 2
4 7
143954125 56574503 3 2
1 ...

output:

772480244
118770152
108641022
615067819
872673860
900276958
951405638
705098808
308078046
912436115
266068466
270465299
858128867
591071828
345756242
253238303
226837537
15366
16188333
896137863
637986485
386483060
601850323
980044594
35
951860846
97816824
379760475
813023811
973778941
948954783
749...

result:

ok 500 lines

Test #8:

score: 0
Accepted
time: 1112ms
memory: 93532kb

input:

500
72235422 449924898 2 4
2 1
2 1
2 1
2 1
826908873 897131377 8 44
7 6
7 5
4 2
7 1
7 2
4 5
7 6
4 2
4 8
7 2
4 3
4 3
4 1
4 5
7 1
7 1
4 3
4 2
7 1
4 3
4 2
4 8
7 8
4 8
7 8
7 1
7 5
7 2
4 2
7 2
4 5
7 6
4 5
7 6
7 8
4 3
7 3
7 3
4 2
4 6
4 8
4 1
4 3
4 5
398346835 179283845 3 4
2 1
2 1
2 1
3 1
146844881 503366...

output:

169993670
63971922
447978336
415747130
17523830
520716693
376879328
858277870
165
142685959
3399
88
339812162
591663632
856960754
861425853
527624471
210
960737551
318751600
197044810
0
0
578594559
980927816
1765
215406311
230128376
3178
155563197
347921715
794781090
928438409
129
890907226
21574705...

result:

ok 500 lines

Test #9:

score: 0
Accepted
time: 1141ms
memory: 93488kb

input:

500
940751563 43705451 3 2
2 1
1 3
4 2 2 1
2 1
756411639 690869710 9 8
3 5
3 6
3 4
5 1
1 7
2 8
3 8
7 9
892465776 834697020 7 6
6 2
4 7
2 3
1 4
5 7
4 3
3649468 246352594 5 4
5 1
5 2
3 2
2 4
927157783 349300522 2 1
2 1
283790347 262369656 8 7
8 6
2 1
7 4
4 3
4 5
2 4
2 6
290590966 415217454 6 5
6 3
4 3...

output:

366369420
13
764641683
869116386
335233317
587724158
945604675
811601159
131513017
113193821
577434289
177358129
220715079
411623223
706865979
34307455
0
1500
273659818
320221078
332322756
811169602
833121521
0
197721600
910924732
638897790
9520
784101624
445798182
313260639
877480788
935885491
9882...

result:

ok 500 lines

Test #10:

score: 0
Accepted
time: 1156ms
memory: 93472kb

input:

500
514300407 782710197 2 1
1 2
872253689 313581735 6 5
3 6
4 5
6 5
3 1
2 4
514655989 526180911 2 1
2 1
813786700 191752057 6 5
3 4
1 2
6 2
3 1
5 4
527846851 580675905 3 2
1 3
1 2
920947549 483871154 4 3
3 4
1 2
4 2
898725255 664985342 7 6
1 5
5 3
3 2
7 6
4 7
4 2
338443592 379946844 6 5
1 6
3 6
4 5
...

output:

359323585
898814710
288847786
98468591
916368235
862413785
267687392
148010090
129433028
849953781
724536941
158837519
498000887
461165396
805773635
983607132
696383636
545900581
14646737
733782
984936679
811469990
529263084
369
536478886
811702967
3930
0
911247824
863805585
857211224
541308891
9855...

result:

ok 500 lines

Test #11:

score: 0
Accepted
time: 1102ms
memory: 93512kb

input:

500
799843967 96204862 10 45
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
3 4
3 5
3 6
3 7
3 8
3 9
3 10
4 5
4 6
4 7
4 8
4 9
4 10
5 6
5 7
5 8
5 9
5 10
6 7
6 8
6 9
6 10
7 8
7 9
7 10
8 9
8 10
9 10
905549873 312183499 10 45
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 3
2 4
2 5
2 6
2 7...

output:

382331873
345030334
53935074
755997739
499731364
338345488
480216832
628179739
857522469
429152121
113184899
431569536
134228466
672765734
335004171
396192449
52161483
51272947
32207679
919199433
449754475
538308198
676557543
394805368
445308710
816052330
946396940
497785742
180220951
694839883
6260...

result:

ok 500 lines

Test #12:

score: 0
Accepted
time: 1107ms
memory: 93512kb

input:

500
1 6 9 6
5 1
5 3
6 3
6 1
6 1
6 7
129420744 661597501 8 62
3 1
3 8
2 8
6 4
3 1
3 4
6 1
2 1
5 7
2 7
5 8
6 4
5 4
6 4
6 8
3 7
5 8
5 4
3 1
5 8
6 1
2 1
6 8
2 7
3 7
5 8
5 7
2 8
6 7
6 8
3 1
5 8
2 4
3 4
2 1
6 1
5 8
3 7
3 7
5 8
5 7
3 8
6 8
5 8
3 8
2 4
5 4
2 1
6 7
3 4
6 1
5 1
5 4
6 1
2 1
2 8
2 4
3 8
3 1
2 8...

output:

0
930302674
918021922
2688
555723867
308858890
178115941
626901301
882938426
64529920
436712258
471977032
1629
519031750
917271881
361955135
292918582
311565484
405
139544991
21
699464930
38420897
33144411
581839840
505691688
148834286
802365483
7110
189465901
592848372
318681400
240
221640557
34180...

result:

ok 500 lines

Test #13:

score: 0
Accepted
time: 1131ms
memory: 93472kb

input:

500
895037311 678092074 7 36
6 7
3 7
2 7
3 7
5 7
3 7
6 7
2 7
3 7
1 7
6 7
5 7
3 7
4 7
2 7
3 7
5 7
3 7
2 7
6 7
6 7
5 7
4 7
3 7
6 7
3 7
1 7
1 7
3 7
5 7
4 7
5 7
4 7
5 7
6 7
7 7
52057757 883729976 10 28
3 10
5 9
5 4
3 6
2 6
5 4
3 6
7 6
1 4
2 8
3 4
3 6
3 6
5 6
2 8
2 8
7 9
7 4
1 8
5 9
5 8
3 9
3 6
1 8
5 9
5...

output:

233161151
894022147
829968933
145964935
114640012
230469791
0
288215752
11174864
549602378
80509321
19017
420581856
605500953
0
2
295236717
924622203
642457490
854013134
236651816
486381351
833520782
404491379
44
605406498
43
871667863
31975295
35649002
672421739
639452328
705236826
630673111
953965...

result:

ok 500 lines

Test #14:

score: 0
Accepted
time: 1111ms
memory: 93484kb

input:

500
468586155 417096820 6 28
5 3
5 2
5 4
5 3
5 4
5 4
5 2
5 4
5 2
5 3
5 4
5 2
5 3
5 6
5 2
5 2
5 6
5 6
5 3
5 3
5 2
5 6
5 3
5 2
5 4
5 6
5 1
5 2
4 2 2 2
2 1
2 2
836098060 22499636 10 34
2 10
4 6
4 9
8 6
2 1
4 5
4 3
8 5
2 7
4 6
2 9
2 7
4 9
2 10
2 9
8 6
2 3
4 7
8 5
4 1
8 3
4 9
2 9
4 7
8 5
8 6
2 10
4 10
8 ...

output:

408372475
7
171802524
325794321
995186738
0
810749469
809308140
503592993
458927433
237386947
0
308217139
56362940
494448309
37021983
704247757
416283140
482723782
732406481
541611906
813899847
24490508
60649103
0
113783786
382459954
410564693
529205101
0
70
845655747
673453250
739070433
718965537
6...

result:

ok 500 lines

Test #15:

score: 0
Accepted
time: 1105ms
memory: 93528kb

input:

500
747167704 715910077 8 33
8 3
8 2
7 4
7 3
7 2
8 2
8 5
8 1
7 3
7 6
7 5
7 5
7 4
7 3
7 5
8 2
8 2
8 3
7 1
8 5
8 3
7 4
7 4
8 5
7 3
7 2
7 3
7 6
7 3
8 1
8 8
7 7
8 8
8 6 7 45
6 3
7 3
1 3
2 3
2 3
6 3
4 3
2 3
4 3
4 3
7 3
6 3
1 3
6 3
5 3
2 3
1 3
7 3
2 3
7 3
7 3
7 3
2 3
7 3
1 3
4 3
1 3
2 3
6 3
4 3
6 3
7 3
2 ...

output:

139000868
71554
4437
5862899
868251513
260
748426030
30865
68605040
761772351
0
473513094
546144530
55875522
566399398
366338948
733745709
42
217357908
943153451
3905154
599124546
214536
963664899
856126292
470011885
961166494
940987796
278320
62817794
127124796
695349606
453191086
721167317
3099025...

result:

ok 500 lines

Test #16:

score: 0
Accepted
time: 1156ms
memory: 93496kb

input:

500
4 3 5 1
4 1
162093547 16388028 5 1
4 5
34200951 73842336 10 1
10 1
612080836 165443639 8 1
6 1
875502793 513974386 5 1
5 2
4 5 1 1
1 1
970988548 370603489 7 1
2 2
649913003 478356148 6 1
1 2
857048420 32835236 8 1
1 8
568473106 750242567 6 1
3 2
99349978 107435592 9 1
9 4
640639938 785592295 2 1...

output:

975
941126669
905787633
588646519
630682622
1
34217585
478055649
598986924
337100781
788706014
65337363
480574552
761393902
1
5262048
1
665
155121072
548027775
1
869369956
250074205
16315293
450144864
1
20
384927068
83991105
110
60355052
37894993
1
991715366
125962320
422610405
54727539
580452366
1
...

result:

ok 500 lines

Extra Test:

score: 0
Extra Test Passed