The publication has been prepared with the support of the ''RUDN University Program 5-100.'' ABSTRACT One of the most promising use cases of 5G/IMT2020 is the unmanned aerial vehicle (UAV). Due to their small size, the UAVs are resource constraint devices. To this end, this paper proposes an offloading algorithm for UAVs to assist in the execution of computationally intensive tasks. The proposed algorithm provides two UAV offloading methods. The first offloading method is the air-offloading, where a UAV can offload its computing tasks to nearby UAVs that have available computing and energy resources. The second offloading method is the ground-offloading, which enables the offloading of tasks to an edge cloud server from the multi-level edge cloud units connected to ground stations. The proposed algorithm is energy-and latency-aware, i.e., it selects the execution device and the offloading method based on the latency and energy constraints. The intensive algorithm simulation over reliable conditions for various scenarios with different cases for each scenario is conducted and results are presented. INDEX TERMS UAV, offloading, latency, energy, 5G, MEC. I. INTRODUCTION Unmanned Aerial Vehicles (UAVs), e.g., drones, have gained increasing interest in recent years [1], [2]. With the near release of fifth generation cellular system (5G), UAVs are expected to have many applications. These applications vary from simple environmental monitoring to the complex high security military applications [3]-[5]. There are many challenges associated with the development of UAV networks and applications. These challenges include [6]-[8]: Trajectory or path planning, collision avoidance, mobility control, cost, security, data offloading, energy consumption, latency and compatibility with existing systems and cellular networks. Part of these challenges is associated with the limited capabilities of UAVs, due to their small size, e.g., microdrones, required for many applications [3]. Applications with computationally intensive tasks and applications, e.g., imageor video-based, require high processing and energy resources, which affect real-time operation and lifetime of an UAV system or even cause task blocking. In order to prolong the The associate editor coordinating the review of this manuscript and approving it for publication was Muhammad Imran.