Click Here to go back to the homepage.

Weak Vertices Solution:


#include <bits/stdc++.h>
using namespace std;

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n;
    cin >> n;
    while(n != -1){
        bool matrix[n][n] = {};
        int num;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cin >> num;
                if(num){
                    matrix[i][j] = true;
                }
            }
        }

        for(int i = 0; i < n;){
            for(int j = 0; j < n; j++){
                //could skip i
                if(matrix[i][j]){
                    for(int k = 0; k < n; k++){
                        if(k == i){
                            continue;
                        }
                        if(matrix[j][k] && matrix[k][i]){
                            goto next;
                        }
                    }
                }
            }
            cout << i << " ";
            next:
            i++;
        }
        cout << endl;
        cin >> n;
    }

    return 0;
}