#include<algorithm> #include<bits/stdc++.h> #ifndef LOCAL #define debug(...) 42 #else #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #endif #define rep1(a) for (int i = 0; i < a; i++) #define rep2(i, a) for (int i = 0; i < a; i++) #define rep3(i, a, b) for (int i = a; i < b; i++) #define rep4(i, a, b, c) for (int i = a; i < b; i += c) #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define pb emplace_back usingnamespace std; template <typename T, typename T2> voidcmin(T &x, const T2 &y){ x = x < y ? x : y; } template <typename T, typename T2> voidcmax(T &x, const T2 &y){ x = x > y ? x : y; } using ll = longlong; using vi = vector<int>; using pii = pair<int, int>; template <classT> using vc = vector<T>; template <classT> using pq = priority_queue<T>; template <classT> using pqg = priority_queue<T, vector<T>, greater<T>>; mt19937 rng(time(NULL)); constint inf = 1000000000; const ll lnf = 1000000000000000000; #define sz(x) int((x).size()) #define all(x) begin(x), end(x) #define fi first #define se second structunionfind { vector<int> p; unionfind(int N) { p = vector<int>(N, -1); } introot(int x){ return p[x] < 0 ? x : p[x] = root(p[x]); } boolsame(int x, int y){ returnroot(x) == root(y); } voidunite(int x, int y){ x = root(x); y = root(y); if (x != y) { if (p[x] < p[y]) { swap(x, y); } p[y] += p[x]; p[x] = y; } } intsize(int x){ return -p[root(x)]; } };
voidsolve(){ int n, m; cin >> n >> m; unionfind f(n * 2); rep(i, m) { int u, v; cin >> u >> v; --u, --v; f.unite(u * 2 + 1, v * 2); debug("unite", u * 2 + 1, v * 2); } vi deg(n * 2); vc<vi> g(n * 2); rep(i, n) { int u = f.root(i * 2); int v = f.root(i * 2 + 1); debug(u,v); deg[v] += 1; g[u].pb(v); } vi val(n * 2, -1); queue<int> q; int c = 0; rep(i, n * 2) if (deg[i] == 0) q.emplace(i); while (!q.empty()) { int u = q.front(); q.pop(); val[u] = c++; for (auto v : g[u]) if (--deg[v] == 0) q.emplace(v); } if (*min_element(all(val)) == -1) { cout << "No\n"; return; } cout << "Yes\n"; rep(i, n) cout << val[f.root(i * 2 + 1)] - val[f.root(i * 2)] << " \n"[i + 1 == n]; }
intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; cin >> t; while (t--) { solve(); } return0; }
#include<bits/stdc++.h> #ifndef LOCAL #define debug(...) 42 #else #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #endif #define rep1(a) for (int i = 0; i < a; i++) #define rep2(i, a) for (int i = 0; i < a; i++) #define rep3(i, a, b) for (int i = a; i < b; i++) #define rep4(i, a, b, c) for (int i = a; i < b; i += c) #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define pb emplace_back usingnamespace std; template <typename T, typename T2> voidcmin(T &x, const T2 &y){ x = x < y ? x : y; } template <typename T, typename T2> voidcmax(T &x, const T2 &y){ x = x > y ? x : y; } using ll = longlong; using vi = vector<int>; using pii = pair<int, int>; template <classT> using vc = vector<T>; template <classT> using pq = priority_queue<T>; template <classT> using pqg = priority_queue<T, vector<T>, greater<T>>; mt19937 rng(time(NULL)); constint inf = 1000000000; const ll lnf = 1000000000000000000; #define sz(x) int((x).size()) #define all(x) begin(x), end(x) #define fi first #define se second
constint P = 1e9 + 7; ll C[40][40]; ll dp[51][220][20]; voidmd(ll &x){ if (x >= P) x -= P; } voidsolve(){ ll N, M, K; cin >> N >> M >> K; dp[50][0][K] = 1; for (int i = 49; i >= 0; i--) { ll lim = M >> i; rep(a, 200) { // exceed from higher bit ll s = (N >> i) - a; rep(b, K + 1) { rep(c, b + 1) { rep(d, K - b + 1) { ll x1 = c + d, x0 = K - x1; ll x = x1 * x0; if (lim == 0 && c > 0) continue; if (lim <= 1 && d > 0) continue; if (x > s) continue; if (s - x & 1) continue; ll a1 = (N >> i + 1) - (s - x) / 2; ll b1 = lim % 2 == 0 ? b - c : K - d; md(dp[i][a][b] += dp[i + 1][a1][b1] * C[b][c] % P * C[K - b][d] % P); } } } } } cout << dp[0][0][K] << "\n"; }