Distributed adaptive nearest neighbor classifier: algorithm and theory