#include using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define pb push_back typedef long long ll; typedef pair pii; typedef vector vi; struct Dinic { struct Edge { int to, rev; ll c, oc; ll flow() { return max(oc - c, 0LL); } // if you need flows }; vi lvl, ptr, q; vector> adj; Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {} void addEdge(int a, int b, ll c, ll rcap = 0) { adj[a].pb({b, sz(adj[b]), c, c}); adj[b].pb({a, sz(adj[a]) - 1, rcap, rcap}); } ll dfs(int v, int t, ll f) { if (v == t || !f) return f; for (int& i = ptr[v]; i < sz(adj[v]); i++) { Edge& e = adj[v][i]; if (lvl[e.to] == lvl[v] + 1) if (ll p = dfs(e.to, t, min(f, e.c))) { e.c -= p, adj[e.to][e.rev].c += p; return p; } } return 0; } ll calc(int s, int t) { ll flow = 0; q[0] = s; rep(L,0,31) do { // 'int L=30' maybe faster for random data lvl = ptr = vi(sz(q)); int qi = 0, qe = lvl[s] = 1; while (qi < qe && !lvl[t]) { int v = q[qi++]; for (Edge e : adj[v]) if (!lvl[e.to] && e.c >> (30 - L)) q[qe++] = e.to, lvl[e.to] = lvl[v] + 1; } while (ll p = dfs(s, t, LLONG_MAX)) flow += p; } while (lvl[t]); return flow; } bool leftOfMinCut(int a) { return lvl[a] != 0; } }; int main() { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; Dinic flow(2*n+2); int source = 2*n; int sink = 2*n+1; for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; flow.addEdge(a, b+n, 5000); flow.addEdge(b, a+n, 5000); } for(int i = 0; i < n; i++) { flow.addEdge(source, i, 5000); flow.addEdge(i+n, sink, 5000); } ll res = flow.calc(source, sink); if(res != n*5000LL) { cout << -1 << "\n"; return 0; } vector> ans(n, vector(n)); for(int from = 0; from < n; from++) { for(auto e : flow.adj[from]) { int to = e.to-n; if(to >= n) continue; ans[from][to] += e.flow(); ans[to][from] += e.flow(); } } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { cout << ans[i][j] << " "; } cout << "\n"; } }