Personal indoor localization with smartphones is a well-researched area, with a number of approaches solving the problem separately for individual users. Most commonly, a particle filter is used to fuse information from dead reckoning and WiFi or Bluetooth adapters to provide an accurate location of the person holding a smartphone. Unfortunately, the existing solutions largely ignore the gains that emerge when a single localization system estimates locations of multiple users in the same environment. Approaches based on filtration maintain only estimates of the current poses of the users, marginalizing the historical data. Therefore, it is difficult to fuse data from multiple individual trajectories that are usually not perfectly synchronized in time. We propose a system that fuses the information from WiFi and dead reckoning employing the graph-based optimization, which is widely applied in robotics. The presented system can be used for localization of a single user, but the improvement is especially visible when this approach is extended to a multi-user scenario. The article presents a number of experiments performed with a smartphone inside an office building. These experiments demonstrate that graph-based optimization can be used as an efficient fusion mechanism to obtain accurate trajectory estimates both in the case of a single user and in a multi-user indoor localization system. The code of our system together with recorded dataset will be made available when the paper gets published.