fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. int main() {
  6. int t, n, m, a[10005], b[10005], c[1005], d[10005];
  7. scanf("%d", &t);
  8. while(t--) {
  9. for(int i=0; i<10005; i++) a[i]=b[i]=d[i]=0;
  10. for(int i=0; i<1005; i++) c[i]=0;
  11. scanf("%d%d", &n, &m);
  12. for(int i=0; i<m; i++) scanf("%d%d", &a[i], &b[i]);
  13. for(int i=m-1; i>=0; i--) if(c[a[i]]==0 && c[b[i]]==0) d[i]++, c[a[i]]++, c[b[i]]++;
  14. for(int i=0; i<m; i++) if(d[i]) printf("%d ", i);
  15. printf("\n");
  16. }
  17. return 0;
  18. }
Success #stdin #stdout 0s 3344KB
stdin
2
4 5
0 1
1 2
2 3
1 3
3 0
4 3
0 1
2 3
2 1
stdout
1 4 
2