Skip to main content

UVa 10928 - My Dear Neighbours


This is simple in-degree counting problem. I decided to use Python 3 for this question due to the split method available in strings.




Code

Language:Python 3

t=int(input())
while t!=0:
 li =[]
 t=t-1
 n=int(input())
 mini=n
 li=list()
 for i in range (n):
  stri=input()
  nos=len(stri.strip().split(" "))
  #print ("Got ", nos)
  if nos < mini:
   mini=nos
   li=list()
   li.append(i+1)
  elif nos == mini:
   li.append(i+1)
 print(*li, sep=' ')
 if t!=0:
  input()

Comments

Popular posts from this blog

Recipe for Union Find in C++ with Path Compression

#include <iostream> #include <iostream> #include<bits/stdc++.h> #define pb push_back #define T 10005 using namespace std; int p[T]; int r[T]; void ini(int n){ for(int i=0;i<n;i++){ p[i]=i; r[i]=1; } } int root(int a){ while(p[a]!=a){ p[a]=p[p[a]]; a=p[a]; } return a; } void j(int a,int b){ if (a==b) return; a=root(a); b=root(b); if (a == b) return; if(r[a]>r[b]){ r[a]+=r[b]; p[b]=a; return; } r[b]+=r[a]; p[a]=b; } bool con(int a, int b){ return p[a]==p[b]; } int main() { std::ios::sync_with_stdio(false); return 0; }