fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. class DSU
  5. {
  6. public :
  7. int n;
  8. vector<int> sz;
  9. vector<int> parent;
  10. DSU (int num)
  11. {
  12. n= num;
  13. sz.resize(num+1,1);
  14. parent.resize(num+1,1);
  15. for(int i=0;i<=num;i++)
  16. {
  17. parent[i]=i;
  18. }
  19. }
  20.  
  21. int findParent (int x)
  22. {
  23. if(x==parent[x])
  24. return x;
  25. else
  26. {
  27. return parent[x]= findParent(parent[x]);
  28. }
  29. }
  30. void unite(int x,int y)
  31. {
  32. int parentX = parent[x];
  33. int parentY = parent[y];
  34. if(sz[parentX] > sz [parentY])
  35. {
  36. parent[parentY]= parentX;
  37. sz[parentX] = sz[parentX] + sz[parentY];
  38. }
  39. else
  40. {
  41. parent[parentX]= parentY;
  42. sz[parentY] = sz[parentY] + sz[parentX];
  43. }
  44. }
  45. };
  46.  
  47. int earliestConnectedTimestamp(vector<string> riders, vector<string> logs)
  48.  
  49. {
  50. int components = riders.size();
  51. DSU dsu(components);
  52. for(auto it : logs)
  53. {
  54. stringstream ss(it);
  55. }
  56. return 0;
  57. }
  58.  
  59. int main() {
  60. // your code goes here
  61. vector<string> riders = {
  62. "Alice",
  63. "Bob",
  64. "Charlie",
  65. "Dan",
  66. "Eve"
  67. };
  68.  
  69. vector<string> logs = {
  70. "1670000001 Alice shared-ride-with Bob",
  71. "1670000042 Charlie shared-ride-with Dan",
  72. "1670000450 Bob shared-ride-with Charlie",
  73. "1670000501 Alice shared-ride-with Eve",
  74. "1670000621 Bob shared-ride-with Dan"
  75. };
  76.  
  77. cout << earliestConnectedTimestamp(riders, logs) << endl;
  78.  
  79. return 0;
  80. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
0