Problem:
Problem M: Settler
Problem
二次元平面上に
N
個の空き地がある。空き地にはそれぞれ1から
N
までの番号が割り振られている。どの空き地もとても小さいので、点とみなすことができる。
i
番目の空き地は(
x
i
,
y
i
)に存在している。
太郎君はこの
N
個の空き地の中からちょうど
K
個を選び、それらの空き地に建物を建てることにした。
  しかし、あまりにも近い場所に複数の建物を建てても面白くないと思ったので、太郎君はそれぞれの空き地どうしのユークリッド距離が必ず2以上となるように空き地を選ぶことにした。
太郎君が選ぶ空き地の組み合わせとして考えられるものを出力するプログラムを作成せよ。
  組み合わせが複数存在する場合は、辞書順で最小のものを出力せよ。
  ただし、どのように
K
個の空き地を選んだとしても、いずれか2つの空き地のユークリッド距離が2より小さくなってしまう場合は、かわりに-1を出力せよ。
Input
入力は以下の形式で与えられる。
N
K
x
1
y
1
x
2
y
2
...
x
N
y
N
Constraints
入力は以下の条件を満たす。
入力は全て整数である。
2 ≤
K
≤
N
≤ 6,000
1 ≤
x
i
,
y
i
≤ 1,000,000    ( 1 ≤
i
≤
N
)
x
i
mod
2 =
floor
(
y
i
÷ 2 )
mod
2 ( 1 ≤
i
≤
N
)
(ここで
floor
(
y
i
÷ 2 ) とは
y
i
を2で割り小数点以下を切り捨てた値である)
同じ座標に複数の空き地が存在することはない。
Output
太郎君が選ぶ空き地の番号を昇順に1行ずつ出力せよ。
Sample Input 1
3 2
2 1
1 2
1 3
Sample Output 1
1
3
Sample Input 2
4 3
2 1
1 2
1 3
2 4
Sample Output 2
-1
Sample Input 3
5 3
5 7
5 6
6 8
20 20
4 8
Sample Output 3
2
3
4

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define MAX 6005

struct Data{
  int a,b,c;
  Data(){    a=b=c=-1;  }
  void insert(int x){
    if(a==x||b==x||c==x)return;
    c=b;
    b=a;
    a=x;
  }
  bool count(int x){
    return (a==x||b==x||c==x);
  }
  int size(){
    return (a>=0)+(b>=0)+(c>=0);
  }
  void erase(int x){
    if(a==x){
      a=b;b=c;c=-1;
    }else if(b==x){
      b=c;c=-1;
    }else if(c==x){
      c=-1;
    }
  }
};

int N,K;
vector<int> G[MAX];
Data g[MAX];

int f[MAX],bs[MAX];
bool visited[MAX];


int px[MAX],py[MAX];


bool dfs(int v){
  visited[v]=true;
  for(int i=0;i<(int)G[v].size();i++){
    int u=G[v][i];
    

    if(f[u]>(int)g[u].size()){
      g[v].insert(u);
      g[u].insert(v);
      return true;
    }
    
    for(int j=0;j<(int)G[u].size();j++){
      int w=G[u][j];
      if(g[u].count(w)==0)continue;
      
      if(!visited[w]&&dfs(w)){
        g[v].insert(u);
        g[u].insert(v);

        g[u].erase(w);
        g[w].erase(u);
        return true;
      }
    }
  }
  return false;
}

void rec(int v,int depth=0){
  if(bs[v]!=-1)return;
  bs[v]=depth%2;
  for(int i=0;i<(int)G[v].size();i++){
    rec(G[v][i],depth+1);
  }
}

int main(){
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>px[i]>>py[i];
    for(int j=0;j<i;j++){
      int X=px[i]-px[j];
      int Y=py[i]-py[j];
      if( abs(X) <=1 && abs(Y)<=1){
        G[i].push_back(j);
        G[j].push_back(i);
      }
    }
  }
  for(int i=0;i<N;i++){
    sort(G[i].begin(),G[i].end());
  }
  
  memset(bs,-1,sizeof(bs));
  for(int i=0;i<N;i++){
    rec(i);
  }
  
  fill(f,f+MAX,1);
  int maxflow=0;
  for(int i=0;i<N;i++){
    if(f[i]==(int)g[i].size())continue;
    memset(visited,false,sizeof(visited));
    if( dfs(i) )maxflow++;
  }
  
  if( N-maxflow < K ){
    cout<<-1<<endl;
    return 0;
  }

    bool ans[MAX]={};
  for(int v=0;v<N;v++){
    bool flg=false;
    for(int i=0;i<(int)G[v].size();i++){
      if( ans[G[v][i]] ){
        flg=true;
      }
    }
    if(flg)continue;
    f[v]=3;
    
    int c=0;
    while(1){
      memset(visited,false,sizeof(visited));
      int a=dfs(v);
      if(a==0)break;
      c++;
    }
    
    if( N - (maxflow+c)>= K ){
      ans[v]=true;
      maxflow+=c;
    }else{
      f[v]=1;
      while(g[v].size()>1){
        int u=g[v].a;
        g[u].erase(v);
        g[v].erase(u);
      }
    }
  }
  
  for(int i=0;i<N;i++){
    if(ans[i]&&K>0){
      cout<<i+1<<endl;
      K--;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 4152
final_rank: 1

code_snippet: #include<iostream>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<stack>
#include<functional>
#define INF 1061109567
#define MOD 998244353
#define EPS 0.000001
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
using namespace std;
typedef long long ll;
int x[6005], y[6005];
int first[6005], nxt[30005], edge[30005], from[30005], w[30005], cnt;
int dep[6005], cur[6005], temp[30005], used[6005], du[6005];
int n, k, s, t;
void init()
{
	memset(first, -1, sizeof(first));
	memset(nxt, -1, sizeof(nxt));
}
void add(int u, int v, int t)
{
	du[u]++;
	from[cnt] = u;
	edge[cnt] = v;
	w[cnt] = t;
	nxt[cnt] = first[u];
	first[u] = cnt++;
}
int dfs(int v, int t, int f, int cnt = INF) {
	if (v == t)return f;
	if (!cnt)return 0;
	used[v] = true;
	for (int i = first[v]; i != -1; i = nxt[i]) {
		int p = edge[i];
		if (!used[p] && w[i] > 0) {
			int d = dfs(p, t, min(f, w[i]), cnt - 1);
			if (d > 0) {
				w[i] -= d;
				w[i ^ 1] += d;
				return d;
			}
		}
	}
	return 0;
}
inline int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)return flow;
		flow += f;
	}
}
bool check(int a, int b)
{
	return (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]) < 4;
}
int main(void)
{
	//freopen("input.txt", "r", stdin);
	init();
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &x[i], &y[i]);
	}
	s = 0, t = n + 1;
	for (int i = 1; i <= n; i++)
	{
		if (y[i] % 2)
		{
			add(s, i, 1);
			add(i, s, 0);
		}
		else
		{
			add(i, t, 1);
			add(t, i, 0);
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (i != j && y[i] % 2 && !(y[j] % 2) && check(i, j))
			{
				add(i, j, INF);
				add(j, i, 0);
			}
		}
	}
	vector<int> ans;
	int flow = max_flow(s, t);
	if (n - flow < k)
	{
		printf("-1\n");
		return 0;
	}
	memcpy(temp, w, cnt * 4);
	for (int i = 1; i <= n; i++)
	{
		if (y[i] % 2)
		{
			int idx;
			for (int j = first[s]; j != -1; j = nxt[j])
			{
				if (edge[j] == i)
					idx = j, w[j] += INF;
			}
			int add_f = 0;
			if (du[i] > 1)
				add_f = max_flow(s, t);
			if (n - (flow + add_f) >= k) ans.push_back(i), flow += add_f, memcpy(temp, w, cnt * 4);
			else memcpy(w, temp, cnt * 4);
		}
		else
		{
			int idx;
			for (int j = first[i]; j != -1; j = nxt[j])
			{
				if (edge[j] == t)
					idx = j, w[j] += INF;
			}
			int add_f = 0;
			if (du[i] > 1)
				add_f = max_flow(s, t);
			if (n - (flow + add_f) >= k) ans.push_back(i), flow += add_f, memcpy(temp, w, cnt * 4);
			else memcpy(w, temp, cnt * 4);
		}
	}
	for (int i = 0; i < k; i++)
		printf("%d\n", ans[i]);
	return 0;
}
accuracy: 1
time_ms: 670
memory_kb: 4212
final_rank: 3

code_snippet: #include<iostream>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<stack>
#include<functional>
#define INF 1061109567
#define MOD 998244353
#define EPS 0.000001
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
using namespace std;
typedef long long ll;
int x[6005], y[6005];
int first[6005], nxt[30005], edge[30005], from[30005], w[30005], cnt;
int dep[6005], cur[6005], temp[30005], used[6005], du[6005];
int n, k, s, t;
void init()
{
	memset(first, -1, sizeof(first));
	memset(nxt, -1, sizeof(nxt));
}
void add(int u, int v, int t)
{
	du[u]++;
	from[cnt] = u;
	edge[cnt] = v;
	w[cnt] = t;
	nxt[cnt] = first[u];
	first[u] = cnt++;
}
int dfs(int v, int t, int f, int cnt = INF) {
	if (v == t)return f;
	if (!cnt)return 0;
	used[v] = true;
	for (int i = first[v]; i != -1; i = nxt[i]) {
		int p = edge[i];
		if (!used[p] && w[i] > 0) {
			int d = dfs(p, t, min(f, w[i]), cnt - 1);
			if (d > 0) {
				w[i] -= d;
				w[i ^ 1] += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)return flow;
		flow += f;
	}
}
bool check(int a, int b)
{
	return (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]) < 4;
}
void text48();
int main(void)
{
	//freopen("input.txt", "r", stdin);
	init();
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &x[i], &y[i]);
	}
	s = 0, t = n + 1;
	for (int i = 1; i <= n; i++)
	{
		if (y[i] % 2)
		{
			add(s, i, 1);
			add(i, s, 0);
		}
		else
		{
			add(i, t, 1);
			add(t, i, 0);
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (i != j && y[i] % 2 && !(y[j] % 2) && check(i, j))
			{
				add(i, j, INF);
				add(j, i, 0);
			}
		}
	}
	vector<int> ans;
	int flow = max_flow(s, t);
	if (n - flow < k)
	{
		printf("-1\n");
		return 0;
	}
	memcpy(temp, w, cnt * 4);
	for (int i = 1; i <= n; i++)
	{
		if (y[i] % 2)
		{
			int idx;
			for (int j = first[s]; j != -1; j = nxt[j])
			{
				if (edge[j] == i)
					idx = j, w[j] += INF;
			}
			int add_f = 0;
			if (du[i] > 1)
				add_f = max_flow(s, t);
			if (n - (flow + add_f) >= k) ans.push_back(i), flow += add_f, memcpy(temp, w, cnt * 4);
			else memcpy(w, temp, cnt * 4);
		}
		else
		{
			int idx;
			for (int j = first[i]; j != -1; j = nxt[j])
			{
				if (edge[j] == t)
					idx = j, w[j] += INF;
			}
			int add_f = 0;
			if (du[i] > 1)
				add_f = max_flow(s, t);
			if (n - (flow + add_f) >= k) ans.push_back(i), flow += add_f, memcpy(temp, w, cnt * 4);
			else memcpy(w, temp, cnt * 4);
		}
	}
	for (int i = 0; i < k; i++)
		printf("%d\n", ans[i]);
	return 0;
}
accuracy: 1
time_ms: 690
memory_kb: 4196
final_rank: 4

code_snippet: #include<iostream>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<stack>
#include<functional>
#define INF 1061109567
#define MOD 998244353
#define EPS 0.000001
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
using namespace std;
typedef long long ll;
int x[6005], y[6005];
int first[6005], nxt[30005], edge[30005], from[30005], w[30005], cnt;
int dep[6005], cur[6005], temp[30005], used[6005];
int n, k, s, t;
void init()
{
	memset(first, -1, sizeof(first));
	memset(nxt, -1, sizeof(nxt));
}
void add(int u, int v, int t)
{
	from[cnt] = u;
	edge[cnt] = v;
	w[cnt] = t;
	nxt[cnt] = first[u];
	first[u] = cnt++;
}
int dfs(int v, int t, int f, int cnt = INF) {
	if (v == t)return f;
	if (!cnt)return 0;
	used[v] = true;
	for (int i = first[v]; i != -1; i = nxt[i]) {
		int p = edge[i];
		if (!used[p] && w[i] > 0) {
			int d = dfs(p, t, min(f, w[i]), cnt - 1);
			if (d > 0) {
				w[i] -= d;
				w[i ^ 1] += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)return flow;
		flow += f;
	}
}
void flow_rev(int s, int t, int f) {
	while (f) {
		memset(used, 0, sizeof(used));
		f -= dfs(s, t, f, 2);
	}
}
bool check(int a, int b)
{
	return (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]) < 4;
}
int main(void)
{
	//freopen("input.txt", "r", stdin);
	init();
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &x[i], &y[i]);
	}
	s = 0, t = n + 1;
	for (int i = 1; i <= n; i++)
	{
		if (y[i] % 2)
		{
			add(s, i, 1);
			add(i, s, 0);
		}
		else
		{
			add(i, t, 1);
			add(t, i, 0);
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (i != j && y[i] % 2 && !(y[j] % 2) && check(i, j))
			{
				add(i, j, INF);
				add(j, i, 0);
			}
		}
	}
	vector<int> ans;
	int flow = max_flow(s, t);
	if (n - flow < k)
	{
		printf("-1\n");
		return 0;
	}
	memcpy(temp, w, cnt * 4);
	for (int i = 1; i <= n; i++)
	{
		if (y[i] % 2)
		{
			int idx;
			for (int j = first[s]; j != -1; j = nxt[j])
			{
				if (edge[j] == i)
					idx = j, w[j] += INF;
			}
			int add_f = max_flow(s, t);
			if (n - (flow + add_f) >= k) ans.push_back(i), flow += add_f, memcpy(temp, w, cnt * 4);
			else memcpy(w, temp, cnt * 4);
		}
		else
		{
			int idx;
			for (int j = first[i]; j != -1; j = nxt[j])
			{
				if (edge[j] == t)
					idx = j, w[j] += INF;
			}
			int add_f = max_flow(s, t);
			if (n - (flow + add_f) >= k) ans.push_back(i), flow += add_f, memcpy(temp, w, cnt * 4);
			else memcpy(w, temp, cnt * 4);
		}
	}
	for (int i = 0; i < k; i++)
		printf("%d\n", ans[i]);
	return 0;
}
accuracy: 1
time_ms: 690
memory_kb: 4208
final_rank: 5

code_snippet: #include<iostream>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<stack>
#include<functional>
#define INF 1061109567
#define MOD 998244353
#define EPS 0.000001
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
using namespace std;
typedef long long ll;
int x[6005], y[6005];
int first[6005], nxt[30005], edge[30005], from[30005], w[30005], cnt;
int dep[6005], cur[6005], temp[30005], used[6005];
int n, k, s, t;
void init()
{
	memset(first, -1, sizeof(first));
	memset(nxt, -1, sizeof(nxt));
}
void add(int u, int v, int t)
{
	from[cnt] = u;
	edge[cnt] = v;
	w[cnt] = t;
	nxt[cnt] = first[u];
	first[u] = cnt++;
}
int dfs(int v, int t, int f, int cnt = INF) {
	if (v == t)return f;
	if (!cnt)return 0;
	used[v] = true;
	for (int i = first[v]; i != -1; i = nxt[i]) {
		int p = edge[i];
		if (!used[p] && w[i] > 0) {
			int d = dfs(p, t, min(f, w[i]), cnt - 1);
			if (d > 0) {
				w[i] -= d;
				w[i ^ 1] += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)return flow;
		flow += f;
	}
}
void flow_rev(int s, int t, int f) {
	while (f) {
		memset(used, 0, sizeof(used));
		f -= dfs(s, t, f, 2);
	}
}
bool check(int a, int b)
{
	return (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]) < 4;
}
int main(void)
{
	//freopen("input.txt", "r", stdin);
	init();
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &x[i], &y[i]);
	}
	s = 0, t = n + 1;
	for (int i = 1; i <= n; i++)
	{
		if (y[i] % 2)
		{
			add(s, i, 1);
			add(i, s, 0);
		}
		else
		{
			add(i, t, 1);
			add(t, i, 0);
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (i != j && y[i] % 2 && !(y[j] % 2) && check(i, j))
			{
				add(i, j, INF);
				add(j, i, 0);
			}
		}
	}
	vector<int> ans;
	int flow = max_flow(s, t);
	if (n - flow < k)
	{
		printf("-1\n");
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		if (y[i] % 2)
		{
			int idx;
			for (int j = first[s]; j != -1; j = nxt[j])
			{
				if (edge[j] == i)
					idx = j, w[j] += INF;
			}
			int add_f = max_flow(s, t);
			if (n - (flow + add_f) >= k) ans.push_back(i), flow += add_f;
			else
			{
				w[idx] -= INF - add_f;
				w[idx ^ 1] -= add_f;
				flow_rev(t, i, add_f);
			}
		}
		else
		{
			int idx;
			for (int j = first[i]; j != -1; j = nxt[j])
			{
				if (edge[j] == t)
					idx = j, w[j] += INF;
			}
			int add_f = max_flow(s, t);
			if (n - (flow + add_f) >= k) ans.push_back(i), flow += add_f;
			else
			{
				w[idx] -= INF - add_f;
				w[idx ^ 1] -= add_f;
				flow_rev(i, s, add_f);
			}
		}
	}
	for (int i = 0; i < k; i++)
		printf("%d\n", ans[i]);
	return 0;
}
accuracy: 1
time_ms: 900
memory_kb: 4100
final_rank: 7

code_snippet: #include<iostream>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<stack>
#include<functional>
#define INF 1061109567
#define MOD 998244353
#define EPS 0.000001
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
using namespace std;
typedef long long ll;
int x[6005], y[6005];
int first[6005], nxt[30005], edge[30005], from[30005], w[30005], cnt;
int dep[6005], cur[6005], temp[30005], used[6005];
int n, k, s, t;
void init()
{
	memset(first, -1, sizeof(first));
	memset(nxt, -1, sizeof(nxt));
}
void add(int u, int v, int t)
{
	from[cnt] = u;
	edge[cnt] = v;
	w[cnt] = t;
	nxt[cnt] = first[u];
	first[u] = cnt++;
}
int dfs(int v, int t, int f, int cnt = INF) {
	if (v == t)return f;
	if (!cnt)return 0;
	used[v] = true;
	for (int i = first[v]; i != -1; i = nxt[i]) {
		int p = edge[i];
		if (!used[p] && w[i] > 0) {
			int d = dfs(p, t, min(f, w[i]), cnt - 1);
			if (d > 0) {
				w[i] -= d;
				w[i ^ 1] += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)return flow;
		flow += f;
	}
}
bool check(int a, int b)
{
	return (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]) < 4;
}
int main(void)
{
	//freopen("input.txt", "r", stdin);
	init();
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &x[i], &y[i]);
	}
	s = 0, t = n + 1;
	for (int i = 1; i <= n; i++)
	{
		if (y[i] % 2)
		{
			add(s, i, 1);
			add(i, s, 0);
		}
		else
		{
			add(i, t, 1);
			add(t, i, 0);
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (i != j && y[i] % 2 && !(y[j] % 2) && check(i, j))
			{
				add(i, j, INF);
				add(j, i, 0);
			}
		}
	}
	vector<int> ans;
	int flow = max_flow(s, t);
	if (n - flow < k)
	{
		printf("-1\n");
		return 0;
	}
	memcpy(temp, w, cnt * 4);
	for (int i = 1; i <= n; i++)
	{
		if (y[i] % 2)
		{
			int idx;
			for (int j = first[s]; j != -1; j = nxt[j])
			{
				if (edge[j] == i)
					idx = j, w[j] += INF;
			}
			int add_f = max_flow(s, t);
			if (n - (flow + add_f) >= k) ans.push_back(i), flow += add_f, memcpy(temp, w, cnt * 4);
			else memcpy(w, temp, cnt * 4);
		}
		else
		{
			int idx;
			for (int j = first[i]; j != -1; j = nxt[j])
			{
				if (edge[j] == t)
					idx = j, w[j] += INF;
			}
			int add_f = max_flow(s, t);
			if (n - (flow + add_f) >= k) ans.push_back(i), flow += add_f, memcpy(temp, w, cnt * 4);
			else memcpy(w, temp, cnt * 4);
		}
	}
	for (int i = 0; i < k; i++)
		printf("%d\n", ans[i]);
	return 0;
}
accuracy: 1
time_ms: 680
memory_kb: 4164
final_rank: 2

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

struct edge {
	int to, cap, rev;
};

vector<edge> G[100000];
bool used[100000];
int banned[100000];
void add_edge(int from, int to) {
	G[from].push_back({ to, 1, (int)G[to].size() });
	G[to].push_back({ from, 0, (int)G[from].size() - 1 });
}

int l, r;
int dfs(int v, int t, int f) {
	if (v == t)return f;
	used[v] = true;
	for (int i = 0; i < (int)G[v].size(); ++i) {
		edge& e = G[v][i];
		if (!used[e.to] && !banned[e.to] &&e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, mod);
		if (f == 0)return flow;
		flow += f;
	}
}
bool isodd[6000];
int flow;
int rest;
void del(int x){
    if(banned[x])return;
    banned[x]=true;
    --rest;
    int nxt = -1;
    if(isodd[x]){
        for(auto& e : G[x]){
            if(e.to == r && e.cap == 0){
                --flow;
                e.cap = 1;
                G[e.to][e.rev].cap = 0;
            }
            else if(e.to != r &&e.cap == 1){
                e.cap = 0;
                G[e.to][e.rev].cap = 1;
                nxt = e.to;
            }
        }
        if(nxt!=-1){
            for(auto& e : G[nxt]){
                if(e.to == l && e.cap == 1){
                    e.cap = 0;
                    G[e.to][e.rev].cap = 1;
                }
            }
        }
    }
    else {
        for(auto& e : G[x]){
            if(e.to == l && e.cap == 1){
                --flow;
                e.cap = 0;
                G[e.to][e.rev].cap = 1;
            }
            else if(e.to != l &&e.cap == 0){
                e.cap = 1;
                G[e.to][e.rev].cap = 0;
                nxt = e.to;
            }
        }
        if(nxt!=-1){
            for(auto& e : G[nxt]){
                if(e.to == r && e.cap == 0){
                    e.cap = 1;
                    G[e.to][e.rev].cap = 0;
                }
            }
        }
    }
}

void add(int x){
    banned[x]=false;
    rest++;
}

void solve() {
	int n, k;
	cin >> n >> k;
	int x[6666], y[6666];
	rep(i, n) {
		cin >> x[i] >> y[i];
    }
	vector<int> odd, even;
	rep(i, n) {
		if (x[i] % 2 ==1 && y[i] % 2 == 0) {
			even.push_back(i);
		}
		else if (x[i] % 2 == 0 && y[i] % 2 == 0) {
			even.push_back(i);
		}
		else odd.push_back(i);
	}
	l = n, r = n + 1;
	rep(i, even.size()) {
		add_edge(l, even[i]);
	}
	rep(j, odd.size()) {
		add_edge(odd[j], r);
		isodd[odd[j]] = true;
	}
	rep(i, even.size()) {
		rep(j, odd.size()) {
			ll dx = x[even[i]] - x[odd[j]];
			ll dy = y[even[i]] - y[odd[j]];
			ll dif = dx * dx + dy * dy;
			if (dif < 4) {
				add_edge(even[i], odd[j]);
			}
		}
	}
	rest = n;
	flow = max_flow(l, r);
	if (n - flow < k) {
		cout << -1 << endl; return;
	}
	vector<int> ans;
    int cur = 0;
    int use = 0;
    while(cur<n){
        if(banned[cur]){
            ++cur;
            continue;
        }
        ++use;
        del(cur);
        vector<int> dels;
        for(auto &e : G[cur]){
            if(e.to!=l&&e.to!=r&&!banned[e.to]){
                dels.push_back(e.to);
                del(e.to);
            }
        }
        flow += max_flow(l, r);
        if(rest-flow+use>=k){
            ans.push_back(cur);
        }
        else {
            --use;
            for(auto e : dels)add(e);
            flow += max_flow(l,r);
        }
        ++cur;
    }
	rep(i,k) {
		cout << ans[i]+1 << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
		return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 6688
final_rank: 8

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;


bool isodd[6000];
vector<int> id;
struct edge {
	int to, cap, rev;
};
vector<edge> G[100000];
bool used[100000];
void add_edge(int from, int to) {
	G[from].push_back({ to, 1, (int)G[to].size() });
	G[to].push_back({ from, 0, (int)G[from].size() - 1 });
}

int l, r;
int dfs(int v, int t, int f) {
	if (v == t)return f;
	used[v] = true;
	for (int i = 0; i < (int)G[v].size(); ++i) {
		edge& e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				if (v != l && e.to != r&&e.to!=l) {
					if (isodd[e.to]) {
						id[v] = e.to;
						id[e.to] = v;
					}
					else {
						if (id[v] == e.to)id[v] = -1;
						if (id[e.to] == v)id[e.to] = -1;
					}
				}
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, mod);
		if (f == 0)return flow;
		flow += f;
	}
}
queue<P> rest;
queue<int> ban;
int num;
vector<bool> exi;
int al; int cdec = 0;
vector<int> aused;
void vanish(int root) {
	while (!ban.empty()) {
		int i = ban.front(); ban.pop();
		aused.push_back(i);
		cdec++;
		exi[i] = false;
		if (id[i] >= 0&&i!=root&&id[i]!=root) {
			int par = id[i];
			edge &e = G[par][0];
			if (isodd[par]) {
				e.cap = 1;
				G[e.to][e.rev].cap = 0;
			}
			else {
				e.cap = 0;
				G[e.to][e.rev].cap = 1;
			}

			id[id[i]] = -1;
			num--;
		}
		id[i] = -1;
		rep(j, G[i].size()) {
			edge &e = G[i][j];
			if (e.cap || G[e.to][e.rev].cap) {
				if (e.to == l) {
					rest.push({ l,e.rev });
				}
				else if (e.to == r) {
					rest.push({ i,j });
				}
				else if (isodd[e.to]) {
					rest.push({ i,j });
				}
				else {
					rest.push({ e.to,e.rev });
				}
			}
			e.cap = 0;
			G[e.to][e.rev].cap = 0;
		}
	}
}
vector<int> xG[6000];
void solve() {
	int n, k;
	cin >> n >> k;
	al = n;
	exi.resize(n+2, true);
	int x[6666], y[6666];
	rep(i, n) {
		cin >> x[i] >> y[i];
	}
	rep(i, n) {
		Rep(j, i + 1, n) {
			ll dx = x[i] - x[j];
			ll dy = y[i] - y[j];
			ll dif = dx * dx + dy * dy;
			if (dif < 4) {
				xG[i].push_back(j);
				xG[j].push_back(i);
				//cout << "connect " << i << " " << j << endl;
			}
		}
	}
	vector<int> odd, even;
	rep(i, n) {
		if (x[i] % 2 ==1 && y[i] % 2 == 0) {
			even.push_back(i);
		}
		else if (x[i] % 2 == 0 && y[i] % 2 == 0) {
			even.push_back(i);
		}
		else odd.push_back(i);
	}
	id.resize(n, -1);
	l = n, r = n + 1;
	rep(i, even.size()) {
		add_edge(l, even[i]);
	}
	rep(j, odd.size()) {
		add_edge(odd[j], r);
		isodd[odd[j]] = true;
	}
	rep(i, even.size()) {
		rep(j, odd.size()) {
			ll dx = x[even[i]] - x[odd[j]];
			ll dy = y[even[i]] - y[odd[j]];
			ll dif = dx * dx + dy * dy;
			if (dif < 4) {
				add_edge(even[i], odd[j]);
			}
		}
	}
	num = max_flow(l, r);
	if (n - num < k) {
		cout << -1 << endl; return;
	}
	//cout << num << endl;
	vector<int> ans;
	int cnt = 0;
	rep(i, n) {
		if (!exi[i])continue;
		cdec = 0;
		//選ぶと仮定
		if (id[i] >= 0) {
			num--; id[id[i]] = -1;
		}
		cnt++;
		ban.push(i);
		rep(j, xG[i].size()) {
			if(exi[xG[i][j]])ban.push(xG[i][j]);
		}
		vanish(i);

		//cout << "hello" << endl;
		//cout << num << endl;
		num += max_flow(l, r);

		al -= cdec;
		//cout << i << " " << num << " "<<al-num<<" "<<k-cnt<<endl;
		if (al-num >= k-cnt) {
			ans.push_back(i);
			while (!rest.empty()) {
				rest.pop();
			}
			aused.clear();
			/*cout << num << endl; cout << al << endl;
			cout << "comb" << endl;
			rep(j, n) {
				cout << j << " " << id[j] << endl;
			}*/

		}
		else {
			al += cdec;
			cnt--;
			while (!rest.empty()) {
				P p = rest.front(); rest.pop();
				G[p.first][p.second].cap = 1;
			}
			rep(j, aused.size()) {
				exi[aused[j]] = true;
			}
			aused.clear();
			num += max_flow(l,r);
		}
	}
	//cout << ans.size() << endl;
	rep(i,k) {
		cout << ans[i]+1 << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	solve();
	//stop
		return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 7000
final_rank: 11

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

int banned[100000];
struct edge {
	int to, cap, rev;
};
vector<edge> G[100000];
bool used[100000];
void add_edge(int from, int to) {
	G[from].push_back({ to, 1, (int)G[to].size() });
	G[to].push_back({ from, 0, (int)G[from].size() - 1 });
}

int l, r;
int dfs(int v, int t, int f) {
	if (v == t)return f;
	used[v] = true;
	for (int i = 0; i < (int)G[v].size(); ++i) {
		edge& e = G[v][i];
		if (!used[e.to] && !banned[e.to] &&e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, mod);
		if (f == 0)return flow;
		flow += f;
	}
}
bool isodd[6000];
int num;
int all;
void del(int x){
    if(banned[x])return;
    banned[x]=true;
    --all;
    int nxt = -1;
    if(isodd[x]){
        for(auto& e : G[x]){
            if(e.to == r && e.cap == 0){
                --num;
                e.cap = 1;
                G[e.to][e.rev].cap = 0;
            }
            else if(e.to != r &&e.cap == 1){
                e.cap = 0;
                G[e.to][e.rev].cap = 1;
                nxt = e.to;
            }
        }
        if(nxt!=-1){
            for(auto& e : G[nxt]){
                if(e.to == l && e.cap == 1){
                    e.cap = 0;
                    G[e.to][e.rev].cap = 1;
                }
            }
        }
    }
    else {
        for(auto& e : G[x]){
            if(e.to == l && e.cap == 1){
                --num;
                e.cap = 0;
                G[e.to][e.rev].cap = 1;
            }
            else if(e.to != l &&e.cap == 0){
                e.cap = 1;
                G[e.to][e.rev].cap = 0;
                nxt = e.to;
            }
        }
        if(nxt!=-1){
            for(auto& e : G[nxt]){
                if(e.to == r && e.cap == 0){
                    e.cap = 1;
                    G[e.to][e.rev].cap = 0;
                }
            }
        }
    }
}

void add(int x){
    banned[x]=false;
    all++;
}


void solve() {
	int n, k;
	cin >> n >> k;
	all = n;
	int x[6666], y[6666];
	rep(i, n) {
		cin >> x[i] >> y[i];
    }
	vector<int> odd, even;
	rep(i, n) {
		if (x[i] % 2 ==1 && y[i] % 2 == 0) {
			even.push_back(i);
		}
		else if (x[i] % 2 == 0 && y[i] % 2 == 0) {
			even.push_back(i);
		}
		else odd.push_back(i);
	}
	l = n, r = n + 1;
	rep(i, even.size()) {
		add_edge(l, even[i]);
	}
	rep(j, odd.size()) {
		add_edge(odd[j], r);
		isodd[odd[j]] = true;
	}
	rep(i, even.size()) {
		rep(j, odd.size()) {
			ll dx = x[even[i]] - x[odd[j]];
			ll dy = y[even[i]] - y[odd[j]];
			ll dif = dx * dx + dy * dy;
			if (dif < 4) {
				add_edge(even[i], odd[j]);
			}
		}
	}
	num = max_flow(l, r);
	if (n - num < k) {
		cout << -1 << endl; return;
	}
	//cout << num << endl;
	vector<int> ans;
    int cur = 0;
    int al = 0;
    while(cur<n){
        if(banned[cur]){
            ++cur;
            continue;
        }

        ++al;
        del(cur);
        vector<int> dels;
        for(auto &e : G[cur]){
            if(e.to!=l&&e.to!=r&&!banned[e.to]){
                dels.push_back(e.to);
                del(e.to);
            }
        }
        num += max_flow(l, r);
        if(all-num+al>=k){
            ans.push_back(cur);
            ++cur;
            continue;
        }
        else {
            --al;
            for(auto e : dels)add(e);
            num += max_flow(l,r);
            ++cur;
            continue;
        }
    }
	//cout << ans.size() << endl;
	rep(i,k) {
		cout << ans[i]+1 << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	solve();
		return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 6596
final_rank: 6

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct FordFulkerson {
  struct edge {
    int to, cap, rev;
    edge(){}
    edge(int to, int cap, int rev):to(to), cap(cap), rev(rev){}
  };
  vector< vector<edge> > graph;
  vector<bool> used;
  FordFulkerson(){}
  FordFulkerson(int V):graph(V), used(V){}
  pair<int, int> add_edge(int from, int to, int cap) {
    graph[from].emplace_back(to, cap, graph[to].size());
    graph[to].emplace_back(from, 0, graph[from].size()-1);
    return make_pair(graph[from].size()-1, graph[to].size()-1);
  }
  int dfs(int v, int t, int f, int k = inf) {
    if(v == t) return f;
    if(k == 0) return 0;
    used[v] = true;
    for(edge& e : graph[v]) {
      if(!used[e.to] && e.cap > 0) {
	int d = dfs(e.to, t, min(f, e.cap), k-1);
	if(d > 0) {
	  e.cap -= d;
	  graph[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  int max_flow(int s, int t, int ff = inf, int k = inf) {
    if(s == t) return 0;
    int flow = 0;
    while(ff) {
      fill(all(used), false);
      int f = dfs(s, t, inf, k);
      if(f == 0) return flow;
      flow += f;
      ff -= f;
    }
    return flow;
  }
};

#define MAX_N 6000

int N, K;
int x[MAX_N], y[MAX_N];

int sq(int x) {
  return x*x;
}

int dist(int i, int j) {
  return sq(x[i]-x[j]) + sq(y[i]-y[j]);
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> K;
  rep(i, N) cin >> x[i] >> y[i];

  int s = N, t = s + 1, V = t + 1;
  FordFulkerson graph(V);
  vector<int> eid(N);
  rep(i, N) {
    if(y[i]%2 == 0) eid[i] = graph.add_edge(s, i, 1).first;
    else eid[i] = graph.add_edge(i, t, 1).first;
    reps(j, i+1, N) {
      if(y[i]%2 != y[j]%2 && dist(i, j) < 4) {
	if(y[i]%2 == 0) graph.add_edge(i, j, inf);
	else graph.add_edge(j, i, inf);
      }
    }
  }

  int mx_st = N - graph.max_flow(s, t);
  if(mx_st < K) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> ans;
  rep(i, N) {
    if(ans.size() == K) break;
    auto& e = y[i]%2 ? graph.graph[i][eid[i]] : graph.graph[s][eid[i]];
    int cap = e.cap;
    int rcap = graph.graph[e.to][e.rev].cap;
    e.cap = inf;
    int f = graph.max_flow(s, t);
    if(mx_st - f >= K) {
      ans.push_back(i);
      mx_st -= f;
    } else {
      e.cap = cap;
      graph.graph[e.to][e.rev].cap = rcap;
      if(y[i]%2 == 0) graph.max_flow(t, i, f, 2);
      else graph.max_flow(i, s, f, 2);
      //graph.max_flow(s, t);
    }
  }

  //assert(ans.size() == K);

  rep(i, K) cout << ans[i]+1 << endl;

  return 0;
}
accuracy: 1
time_ms: 870
memory_kb: 4452
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define MAX_V 6005
#define INF (1e9)
using namespace std;
typedef long long ll;

struct edge{int to, cap, rev;};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});  
}

int dfs(int v,int t,int f,int cnt=INF){
  if(v == t)return f;
  if(!cnt)return 0;
  used[v]=true;
  for(int i=0; i<G[v].size() ;i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to ,t , min(f,e.cap),cnt-1);
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}

void flow_rev(int s,int t,int f){
  while(f){
    memset(used,0,sizeof(used));
    f-=dfs(s,t,f,2);
  }
}

ll n,k,x[MAX_V],y[MAX_V],s,t;

bool check_dis(int A,int B){
  return (x[A]-x[B])*(x[A]-x[B])+(y[A]-y[B])*(y[A]-y[B])<4;
}

void make_graph(){
    
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(i!=j&&y[i]%2&&!(y[j]%2)&&check_dis(i,j))add_edge(i,j,INF);

  s=n, t=n+1;
  for(int i=0;i<n;i++)
    if(y[i]%2)add_edge(s,i,1);
    else add_edge(i,t,1);
  
}

vector<int> ans;

void solve(){
  int F=max_flow(s,t);
  
  if(n-F<k){
    cout<<-1<<endl;
    return;
  }

  for(int i=0;i<n;i++){
    
    if(y[i]%2){
      int idx;
      for(int j=0;j<G[s].size();j++)
	if(G[s][j].to==i)idx=j,G[s][j].cap+=INF;
      
      int add_F=max_flow(s,t);
      if(n-(F+add_F)>=k)ans.push_back(i+1),F+=add_F;
      else{
	edge &e=G[s][idx];
	e.cap-=INF-add_F;
	G[e.to][e.rev].cap-=add_F;
	
	flow_rev(t,i,add_F);
      }
      
    }else{
      int idx;
      for(int j=0;j<G[i].size();j++)
	if(G[i][j].to==t)idx=j,G[i][j].cap+=INF;
      
      int add_F=max_flow(s,t);
      if(n-(F+add_F)>=k)ans.push_back(i+1),F+=add_F;
      else{
	edge &e=G[i][idx];
	e.cap-=INF-add_F;
	G[e.to][e.rev].cap-=add_F;
	
	flow_rev(i,s,add_F);
      }
      
    }
    
  }
  for(int i=0;i<k;i++)cout<<ans[i]<<endl;
}

int main(){
  cin>>n>>k;
  for(int i=0;i<n;i++)cin>>x[i]>>y[i];
  
  make_graph();

  solve();
  
  return 0;
}
accuracy: 1
time_ms: 860
memory_kb: 4388
final_rank: 9