Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct Con{
- int val;
- int layer;
- };
- int n;
- string grid;
- vector<int> adj[1001];
- int C[1001];
- int ans;
- bool visited[1001];
- queue<Con> q;
- int main(){
- //freopen("treewidth.in", "r", stdin);
- cin >> n;
- for(int i=0; i<n; i++){
- cin >> grid;
- for(int j=0; j<n; j++){
- if(grid[j] == '1'){
- adj[i+1].push_back(j+1);
- }
- }
- }
- q.push({1, 0});
- visited[1] = true;
- while(!q.empty()){
- Con cur = q.front();
- q.pop();
- //cout << cur.val << ", " << cur.layer << '\n';
- C[cur.layer]++;
- ans = max(ans, C[cur.layer]);
- for(auto v: adj[cur.val]){
- if(!visited[v]){
- visited[v] = true;
- q.push({v, cur.layer+1});
- }
- }
- }
- cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement