結果

問題 No.2985 May Count Induced C4 Subgraphs
ユーザー wsrtrtwsrtrt
提出日時 2024-12-13 05:20:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 22,297 bytes
コンパイル時間 5,912 ms
コンパイル使用メモリ 320,676 KB
実行使用メモリ 813,940 KB
最終ジャッジ日時 2024-12-13 05:22:18
合計ジャッジ時間 77,751 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
418,284 KB
testcase_02 WA -
testcase_03 AC 2 ms
10,496 KB
testcase_04 AC 2 ms
417,988 KB
testcase_05 MLE -
testcase_06 TLE -
testcase_07 MLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 471 ms
40,812 KB
testcase_16 WA -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define INT(...)                                                                                                                                               \
    int __VA_ARGS__;                                                                                                                                           \
    IN(__VA_ARGS__)
#define LL(...)                                                                                                                                                \
    ll __VA_ARGS__;                                                                                                                                            \
    IN(__VA_ARGS__)
#define STR(...)                                                                                                                                               \
    string __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
#define CHR(...)                                                                                                                                               \
    char __VA_ARGS__;                                                                                                                                          \
    IN(__VA_ARGS__)
#define DBL(...)                                                                                                                                               \
    double __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
#define ll long long
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define pii pair<int, int>
#define pll pair<long long,long long>
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<long long>
#define vc vector<char>
#define vvi vector<vector<int>> 
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size)                                                                                                                                  \
    vector<type> name(size);                                                                                                                                   \
    IN(name)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {
    scan(head);
    IN(tail...);
}
template <class T> void print(const T &a) { cout << a; }
void OUT() { cout << endl; }
template <class Head, class... Tail> void OUT(const Head &head, const Tail &...tail) {
    print(head);
    if(sizeof...(tail)) cout << ' ';
    OUT(tail...);
}
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)                                                                                                                                   \
    vector<vector<type>> name(h, vector<type>(w));                                                                                                             \
    IN(name)
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)                                                                                                                         \
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> pair<T, T> operator-(const pair<T, T> &x, const pair<T, T> &y) { return pair<T, T>(x.ff - y.ff, x.ss - y.ss); }
template <class T> pair<T, T> operator+(const pair<T, T> &x, const pair<T, T> &y) { return pair<T, T>(x.ff + y.ff, x.ss + y.ss); }
template <class T> pair<T, T> operator&(const pair<T, T> &l, const pair<T, T> &r) { return pair<T, T>(max(l.ff, r.ff), min(l.ss, r.ss)); }
template <class T> vector<T> &operator--(vector<T> &v) {
    fore(e, v) e--;
    return v;
}
template <class T> vector<T> operator--(vector<T> &v, int) {
    auto res = v;
    fore(e, v) e--;
    return res;
}
template <class T> vector<T> &operator++(vector<T> &v) {
    fore(e, v) e++;
    return v;
}
template <class T> vector<T> operator++(vector<T> &v, int) {
    auto res = v;
    fore(e, v) e++;
    return res;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
//座標圧縮
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    UNIQUE(y);
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
template <class T> T ceil(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <class T> T floor(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? x / y : (x + y - 1) / y);
}
long long POW(long long x, int n) {
    long long res = 1LL;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
//0^n=0
long long modpow(long long a, long long n, long long mod) {
    a%=mod;
    assert(a!=0||n!=0);
    if(a==0)return 0;
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//return 0<=a&&a<h&&0<=b&&b<w;
inline bool ingrid(ll a,ll b,ll h,ll w){return 0<=a&&a<h&&0<=b&&b<w;}
//return 0<=a&&a<n;
inline bool inl(int a,int n){return 0<=a&&a<n;}
// bit 演算系
ll pow2(int i) { return 1LL << i; }
int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
int topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
int lowbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); }
int lowbit(ll a) { return a == 0 ? 64 : __builtin_ctzll(a); }
// int allbit(int n) { return (1 << n) - 1; }
ll allbit(ll n) { return (1LL << n) - 1; }
int popcount(signed t) { return __builtin_popcount(t); }
int popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(int i) { return i && (i & -i) == i; }
int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}
long long sqrtll(long long x) {
    assert(x >= 0);
    long long rev = sqrt(x);
    while(rev * rev > x) --rev;
    while((rev+1) * (rev+1)<=x) ++rev;
    return rev;
}
int logN(long long n){
    int ret=1;
    while((1LL<<ret)<n)ret++;
    return ret;
}
const double PI=3.1415926535897932384626433832795028841971;
const ll MOD998 = 998244353;
const int INFI = numeric_limits<int>::max() / 2; const long long INFL = numeric_limits<long long>::max() / 2;
#define inf INFINITY

template<class T>
void debug(vector<T> a){
    rep(i,0,(int)a.size()){
        cout<<a[i]<<' ';
    }
    cout<<endl;
    return;
}

bool palindrome(const string& s){
    return equal(all(s),s.rbegin());
}

template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;
public:
    u64 a;
    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &val() noexcept { return a; }
    constexpr const u64 &val() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
        if (exp % 2) {
          *this *= rhs;
        }
        rhs *= rhs;
        exp /= 2;
        }
        return *this;
    }
    friend bool operator==(const modint& a,const modint& b) { return a.val()==b.val(); }
    friend bool operator!=(const modint& a,const modint& b) { return a.val()!=b.val(); }
};
using mint9=modint<998244353>;
using mint1=modint<1000000007>;

//costを指定しないと重みなし辺になります
struct Edge{
    int from,to;
    ll cost;
    Edge()=default;
    Edge(int from,int to,ll cost=1):from(from),to(to),cost(cost){}
    operator int() const {return to;}
};

constexpr pii dx4[4] = {pii{-1, 0},pii{0, -1}, pii{0, 1}, pii{1, 0} };
constexpr pii dx8[8] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
constexpr pii dx[100]={{1,0},{0,1},{1,1},{0,0}};

#define el "\n"
#define endl "\n"
#define fastio std::cin.sync_with_stdio(false);std::cin.tie(nullptr);

vll bf(int n,int m,vi &u,vi &v){
    vector<set<int>> g(n);
    rep(i,0,m){
        int a,b;tie(a,b)={u[i],v[i]};
        g[a].insert(b);g[b].insert(a);
    }
    
    auto con=[&](int a,int b){
        return g[a].find(b)!=g[a].end();
    };
    vll ans(11);
    
    rep(A,0,n){
        rep(B,A+1,n){
            rep(C,B+1,n){
                rep(D,C+1,n){
                    vi a={A,B,C,D};
                    vi deg(4);
                    int cnt{};
                    rep(i,0,4){
                        rep(j,i+1,4){
                            if(i==j)continue;
                            if(con(a[i],a[j])){
                                deg[i]++;
                                deg[j]++;
                                cnt++;
                            }
                        }
                    }
                    if(SUM(deg)==12)ans[10]++;
                    else if(MAX(deg)==0)ans[0]++;
                    else if(cnt==1)ans[1]++;
                    else if(cnt==2){
                        if(MAX(deg)==2)ans[2]++;
                        else ans[3]++;
                    }else if(cnt==3){
                        if(MAX(deg)==3)ans[4]++;
                        else if(MIN(deg)==0)ans[6]++;
                        else ans[5]++;
                    }else if(cnt==4){
                        if(MAX(deg)==MIN(deg)&&MAX(deg)==2)ans[7]++;
                        else ans[8]++;
                    }else ans[9]++;
                }
            }
        }
    }
    return ans;
}
//{1,1,1,1,1,1,1,1,1,1,1}
mint9 solveVec1(int n,int m){
    mint9 res=1;
    rep(i,0,4)res*=n-i;
    rep(i,1,4+1)res/=i;
    return res;
}
//{0,1,2,2,3,3,3,4,4,5,6}
mint9 solveVec2(int n,int m){
    mint9 res=12*m;
    rep(i,0,2)res*=n-i-2;
    res/=24;
    return res;
}
vector<ll> deg;
//{0,0,1,0,3,2,3,4,5,8,12},
mint9 solveVec3(int n,int m,vi &u,vi &v){
    mint9 res=0;
    deg.resize(n);
    rep(i,0,m){
        deg[u[i]]++;deg[v[i]]++;
    }
    rep(i,0,n){
        res+=(deg[i]-1)*deg[i]/2;
    }
    res*=(n-3);
    return res;
}
//{0,0,0,1,0,1,0,2,1,2,3}
mint9 solveVec4(int n,int m,vi &u,vi &v){
    mint9 res=0;
    rep(i,0,m){
        res+=(m-deg[u[i]]-deg[v[i]]+1);
    }
    res/=2;
    return res;
}
//{0,0,0,0,1,0,0,0,1,2,4}
mint9 solveVec5(int n,int m,vi &u,vi &v){
    mint9 res=0;
    rep(i,0,n){
        if(deg[i]>=3){
            mint9 tmp=deg[i]*(deg[i]-1);tmp*=(deg[i]-2);
            tmp/=6;
            res+=tmp;
        }
    }
    return res;
}

template<class G>
vector<tuple<int,int,int>> EnumerateTriangles(G& g){
    int n=g.size();
    vector<vector<int>> h(n);
    vector<int> deg(n);
    for(int i=0;i<n;i++){
        for(int &j:g[i]){
            deg[i]++;
            deg[j]++;
        }
    }
    for(int i=0;i<n;i++){
        for(int &j:g[i]){
            if((deg[i]==deg[(int)j] && i < (int)j) || deg[i] < deg[(int)j]){
                h[i].push_back((int)j);
            }
        }
    }
    vector<tuple<int,int,int>> res;
    vector<int> flag(n);
    for(int i=0;i<n;i++){
        for(int &j:h[i]){
            flag[(int)j] = 1;
        }
        for(int &j:h[i]){
            for(int &k:h[(int)j]){
                if(flag[(int)k])res.emplace_back(i,j,k);
            }
        }
        for(int &j:h[i]){
            flag[(int)j] = 0;
        }
    }
    return res;
};
/*
辺の数を M として三角形の数は高々 Msqrt(2M) 個
グラフの三角形をO(Msqrt(M))で列挙できる
辺の向きを(次数の小さい頂点)->(次数の大きい頂点)とすることで出次数をいい感じに抑えつつ
DAGにできる
参考
https://ei1333.github.io/library/graph/others/enumerate-triangles.hpp.html
https://www.slideshare.net/slideshow/trianguler/38443802#58
*/
vector<tuple<int,int,int>> tr;
//{0,0,0,0,0,1,0,4,2,6,12}
mint9 solveVec6(int n,int m,vi u,vi v){
    mint9 res=0;
    rep(i,0,m){
        res+=(deg[u[i]]-1)*(deg[v[i]]-1);
    }
    res-=3*(ll)tr.size();
    return res;
}

//{0,0,0,1,0,1,0,2,1,2,3},
mint9 solveVec7(int n,int m,vi &u,vi &v){
    mint9 res=tr.size();
    res*=(n-3);
    return res;
}


vector<ll> cnt_a;
vector<ll> cnt_b;
vector<ll> cnt_c;
vll cnt;
//{0,1,0,2,0,0,0,0,0,0,0},
mint9 solveVec8(int n,int m,vi u,vi v){
    mint9 res=0;
    constexpr ll B=64;
    using ull=unsigned long long;
    constexpr int MAXN=200000;
    constexpr int blocks=((MAXN+B-1)>>6);
    cnt_a.resize(m,-1);
    cnt_b.resize(m,-1);
    cnt.resize(m,n);
    cnt_c.resize(m);
    ull g[MAXN];
    rep(i,0,blocks){
        memset(g,0,sizeof(g));
        rep(j,0,m){
            if(i==(v[j]>>6))g[u[j]]|=(1ull<<(v[j]&(63)));
            if(i==(u[j]>>6))g[v[j]]|=(1ull<<(u[j]&(63)));
        }
        rep(j,0,m){
            cnt[j]-=__builtin_popcountll(g[u[j]]|g[v[j]]);
            cnt_a[j]+=__builtin_popcountll(g[u[j]]&(~g[v[j]]));
            cnt_b[j]+=__builtin_popcountll(g[v[j]]&(~g[u[j]]));
            cnt_c[j]+=__builtin_popcountll(g[u[j]]&g[v[j]]);
        }
    }
    rep(i,0,m){
        res+=cnt[i]*(cnt[i]-1)/2;
    }
    return res;
}


//{0,0,0,0,0,0,0,0,1,4,12}
mint9 solveVec9(int n,int m,vi &u,vi &v){
    vi tdeg(n);
    fore(i,tr){
        int a,b,c;tie(a,b,c)=i;
        tdeg[a]++;
        tdeg[b]++;
        tdeg[c]++;
    }
    mint9 res=0;
    rep(i,0,m){
        res+=tdeg[u[i]]+tdeg[v[i]];
    }
    res-=6*(ll)tr.size();
    return res;
}
//{0,0,0,0,0,0,0,0,0,1,6}
mint9 solveVec10(int n,int m,vi &u,vi &v){
    map<pii,int> mp;
    rep(i,0,m){
        mp[{min(u[i],v[i]),max(u[i],v[i])}]=i;
    }
    vll cnt(m);
    fore(i,tr){
        int a,b,c;tie(a,b,c)=i;
        cnt[mp[{min(a,b),max(a,b)}]]++;
        cnt[mp[{min(b,c),max(b,c)}]]++;
        cnt[mp[{min(a,c),max(a,c)}]]++;
    }
    mint9 res=0;
    rep(i,0,m){
        res+=(cnt[i]-1)*(cnt[i])/2;
    }
    return res;
}

//{0,0,0,0,0,1,0,4,0,0,0}
mint9 solveVec11(int n,int m,vi&u,vi& v){
    mint9 res=0;
    rep(i,0,m){
        res+=cnt_a[i]*cnt_b[i];
    }
    return res;
}

//{0,0,0,0,3,0,0,0,1,0,0}
mint9 solveVec12(int n,int m,vi &u,vi &v){
    mint9 res=0;
    rep(i,0,m){
        res+=(cnt_a[i]-1)*(cnt_a[i])/2;
        res+=(cnt_b[i]-1)*(cnt_b[i])/2;
    }
    return res;
}
//{0,0,0,0,0,0,3,0,1,0,0}
mint9 solveVec13(int n,int m,vi &u,vi &v){
    mint9 res=0;
    rep(i,0,m){
        res+=cnt_c[i]*(cnt[i]);
    }
    return res;
}

class CountingC4 {
private:
    int V, threshold;
    vector<vector<int> > G;
    vector<vector<array<int, 2> > > memo;
    vector<int> flag1, flag2;
    void process_high_degree(long long& ans){
        for(int i = 0; i < V; ++i){
            if((int)G[i].size() <= threshold) continue;
            for(const int u : G[i]){
                if(u > i) flag1[u] = 1;
                flag2[u] = 1;
            }
            for(int j = 0; j < i; ++j){
                if((int)G[j].size() > threshold) continue;
                long long cnt1 = 0, cnt2 = 0;
                for(const int u : G[j]){
                    if(u < j || !flag2[u]) continue;
                    if((int)G[u].size() > threshold) ++cnt1;
                    else ++cnt2; 
                }
                ans += (cnt1 + cnt2) * (cnt1 + cnt2 - 1) / 2;
            }
            for(int j = i + 1; j < V; ++j){
                long long cnt = 0;
                for(const int u : G[j]){
                    if(flag1[u]) ++cnt;
                }
                ans += cnt * (cnt - 1) / 2;
            }
            for(const int u : G[i]) flag1[u] = flag2[u] = 0;
        }
    }
    void process_low_degree(long long& ans){
        for(int i = 0; i < V; ++i){
            if((int)G[i].size() > threshold) continue;
            for(const int u : G[i]){
                for(const int v : G[i]){
                    if(v > u) memo[u].push_back({i, v});
                }
            }
        }
        for(int i = 0; i < V; ++i){
            for(const auto& e : memo[i]){
                if(e[0] < i) ++flag1[e[1]];
                else ++flag2[e[1]];
            }
            for(const auto& e : memo[i]){
                ans += (long long)(flag1[e[1]] + 2 * flag2[e[1]] - 1) * flag1[e[1]] / 2;
                flag1[e[1]] = flag2[e[1]] = 0;
            }
        }
    }
public:
    CountingC4(const int node_size)
         : V(node_size), threshold(0), G(V), memo(V), flag1(V, 0), flag2(V, 0){}
    void add_edge(const int u, const int v){
        G[u].push_back(v), G[v].push_back(u);
        ++threshold;
    }
    long long solve(){
        threshold = floor(sqrt(2 * threshold)) / 2;
        long long ans = 0;
        process_high_degree(ans);
        process_low_degree(ans);
        return ans;
    }
};

//{0,0,0,0,0,0,0,1,0,1,3}
mint9 solveVec14(int n,int m,vi &u,vi &v){
    CountingC4 cc(n);
    rep(i,0,m){
        cc.add_edge(u[i],v[i]);
    }
    mint9 res=cc.solve();
    return res;
}
long long modinv(long long a, long long mod) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a/b;
        a -= t*b; swap(a, b);
        u -= t*v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

// matrix
template<int MOD> struct Matrix {
    vector<vector<long long> > val;
    Matrix(int n, int m, long long x = 0) : val(n, vector<long long>(m, x)) {}
    void init(int n, int m, long long x = 0) {val.assign(n, vector<long long>(m, x));}
    size_t size() const {return val.size();}
    inline vector<long long>& operator [] (int i) {return val[i];}
};

template<int MOD> int GaussJordan(Matrix<MOD> &A, bool is_extended = false) {
    int m = A.size(), n = A[0].size();
    for (int row = 0; row < m; ++row)
        for (int col = 0; col < n; ++col)
            A[row][col] = (A[row][col] % MOD + MOD) % MOD;
    
    int rank = 0;
    for (int col = 0; col < n; ++col) {
        if (is_extended && col == n-1) break;
        int pivot = -1;
        for (int row = rank; row < m; ++row) {
            if (A[row][col] != 0) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        auto inv = modinv(A[rank][col], MOD);
        for (int col2 = 0; col2 < n; ++col2)
            A[rank][col2] = A[rank][col2] * inv % MOD;
        for (int row = 0; row < m; ++row) {
            if (row != rank && A[row][col]) {
                auto fac = A[row][col];
                for (int col2 = 0; col2 < n; ++col2) {
                    A[row][col2] -= A[rank][col2] * fac % MOD;
                    if (A[row][col2] < 0) A[row][col2] += MOD;
                }
            }
        }
        ++rank;
    }
    return rank;
}

void solve(ll n,ll m,vi &u,vi &v){
    vector<vector<int>> g(n);
    rep(i,0,m){
        g[u[i]].pb(v[i]);
        g[v[i]].pb(u[i]);
    }
    tr=EnumerateTriangles(g);
    Matrix<998244353> mt(10,12);
    mint9 tmp=1;
    rep(i,0,4)tmp*=(n-i),tmp/=i+1;
    mt.val={
{1,1,1,1,1,1,1,1,1,1,1,(ll)tmp.val()}, 
{0,1,2,2,3,3,3,4,4,5,6,(ll)solveVec2(n,m).val()},
{0,0,1,0,3,2,3,4,5,8,12,(ll)solveVec3(n,m,u,v).val()},
{0,0,0,1,0,1,0,2,1,2,3,(ll)solveVec4(n,m,u,v).val()},
{0,0,0,0,1,0,0,0,1,2,4,(ll)solveVec5(n,m,u,v).val()},
{0,0,0,0,0,1,0,4,2,6,12,(ll)solveVec6(n,m,u,v).val()},
{0,0,0,0,0,0,1,0,1,2,4,(ll)solveVec7(n,m,u,v).val()},
{0,0,0,0,0,0,0,1,0,1,3,(ll)solveVec14(n,m,u,v).val()},
{0,0,0,0,0,0,0,0,1,4,12,(ll)solveVec9(n,m,u,v).val()},
{0,0,0,0,0,0,0,0,0,1,6,(ll)solveVec10(n,m,u,v).val()}
};
GaussJordan(mt,1);
mint9 ans=mt[0].back();
mint9 p=1;p/=3;
cout<<p.val()<<' ';
ans-=p*mt[7].back();
cout<<ans.val()<<' ';
cout<<endl;
}

int main(){
    fastio
    INT(n,m);
    vi u(m),v(m);
    rep(i,0,m){
        IN(u[i],v[i]);
    }
    u--;v--;
    solve(n,m,u,v);
	return 0; 
}
/*
{
{1,1,1,1,1,1,1,1,1,1,1}, 
{0,1,2,2,3,3,3,4,4,5,6},
{0,0,1,0,3,2,3,4,5,8,12},
{0,0,0,1,0,1,0,2,1,2,3},
{0,0,0,0,1,0,0,0,1,2,4},
{0,0,0,0,0,1,0,4,2,6,12},
{0,0,0,0,0,0,1,0,1,2,4},
{0,0,0,0,0,0,0,1,0,1,3},
{0,0,0,0,0,0,0,0,1,4,12},
{0,0,0,0,0,0,0,0,0,1,6}
};
*/
0