1 solutions
-
0
C++ :
#include<bits/stdc++.h> using namespace std; const int N = 510; vector<int> g[N*21]; bool vis[N*21]; int cnt[N][30]; void dfs(int pos , int fa , int k){ for (int i = 0 ; i < g[pos].size() ; i++){ int to = g[pos][i]; if (vis[to]) continue; vis[to] = true; cnt[fa][k]++; dfs(to,fa,k+1); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,m,k; cin >> n >> m >> k; for (int i = 1 ; i <= m ; i++){ int u,v; cin >> u >> v; for (int j = 0 ; j < k ; j++){ int u1 = u + j * n; int v1 = v + j * n; int u2 = u + (j+1) * n; int v2 = v + (j+1) * n; g[u1].push_back(v2); g[v1].push_back(u2); } } for (int i = 1 ; i <= n ; i++){ memset(vis,0,sizeof(vis)); dfs(i,i,1); for (int j = 1 ; j <= k ; j++) cout << cnt[i][j] << " "; cout << endl; } return 0; }
- 1
Information
- ID
- 126
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By