View Code of Problem 131

#include <bits/stdc++.h>

using namespace std;

int map1[550][550],degree[550];

int n,m;

void init(){
    memset(map1,0, sizeof(map1));
    memset(degree,0,sizeof(degree));
}

int main(){
    while (~scanf("%d%d",&n,&m)){
        init();
        int temp1,temp2;
        for (int i=0;i<m;i++){
            scanf("%d%d",&temp1,&temp2);
            map1[temp1][temp2]=1;
            degree[temp2]++;
        }
        int cnt=n,zero;
        while (cnt){
            cnt--;
            zero=-1;
            for (int i=1;i<=n;i++){
                if (degree[i]==0){
                    zero=i;
                }
            }
            if(zero==-1 && cnt){
                printf("ERROR\n");
                break;
            }
            degree[zero]=-1;
            for (int i=1;i<=n;i++){
                if (map1[zero][i]==1){
                    map1[zero][i]=0;
                    degree[i]--;
                }
            }
        }
        if (cnt==0){
            printf("RIGHT\n");
        }
    }
}

Double click to view unformatted code.


Back to problem 131