Untitled
unknown
plain_text
2 years ago
1.2 kB
1
Indexable
// In Practice, You should use the statndard input/output // in order to receive a score properly. // Do not use file input and output. Please be very careful. #include<iostream> using namespace std; int N; int map[105][105]; void nhap(){ for(int i=0; i<N; i++){ for(int j=0; j<N; j++){ cin>>map[i][j]; } } } int main(int argc, char** argv) { int test_case; int T; freopen("text.txt", "r", stdin); cin >> T; /* Read each test case from standard input. */ for(test_case = 1; test_case <= T; ++test_case) { int ans=0; cin>>N; nhap(); int no_edge; int selected[100]; selected[0] = true; no_edge=0; while (no_edge < N - 1) { int min = 100000; int x = 0; int y = 0; for (int i = 0; i < N; i++) { if (selected[i]) { for (int j = 0; j < N; j++) { if (!selected[j] && map[i][j]) { // not in selected and there is an edge if (min > map[i][j]) { min = map[i][j]; x = i; y = j; } } } } } ans+=map[x][y]; selected[y] = true; no_edge++; } cout<<ans; } return 0;//Your program should return 0 on normal termination. }
Editor is loading...