Untitled
unknown
plain_text
a year ago
1.1 kB
2
Indexable
Never
#include<iostream> using namespace std; int T, n; int arr[1005][1005], visit[1005], a; int rs, maxx, kq; void nhap(){ cin >> n; for(int i = 0; i < n; i ++) { for(int j = 0; j < n; j ++) { arr[i][j] = 0; } } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j ++) { cin >> a; if(a == 1) { arr[i][0] ++; arr[i][arr[i][0]] = j; } } } } void reset(){for(int i=0;i<n;i++)visit[i]=0;} void dequy(int x, int t){ for(int i = 1; i <= arr[x][0]; i ++) { if(!visit[arr[x][i]] && arr[x][i] != t) { visit[arr[x][i]] = 1; dequy(arr[x][i], t); } } } int main() { //freopen("input.txt", "r", stdin); ios::sync_with_stdio(false); cin >> T; for(int t = 1; t <= T; t ++){ nhap(); maxx = 1; kq = 0; for(int i = 0; i < n; i ++) { reset(); rs = 0; for(int j = 0; j < n; j ++) { if(!visit[j] && i != j) { visit[j] = 1; dequy(j,i); rs ++; } } if(rs > maxx) { kq = i + 1; maxx = rs; } } cout << kq << endl; } return 0; }