Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4.  
  5. using namespace std;
  6. struct sub{
  7.     int a=0;
  8.     int b=0;
  9.     int t= 0;
  10. };
  11. struct temp{
  12.     int num,time;
  13. };
  14. temp finda(int b, vector<sub> sys){
  15.     int mint = 1005;
  16.     int num = -1;
  17.     for(int i =0;i<sys.size();i++){
  18.         if(sys[i].b == b && sys[i].t<mint){
  19.             mint = sys[i].t;
  20.             num = sys[i].a;
  21.         }
  22.     }
  23.     temp x = {num,mint};
  24.     return x;
  25. }
  26.  
  27. temp findb(int a, vector<sub> sys){
  28.     int mint = 1005;
  29.     int num = -1;
  30.     for(int i =0;i<sys.size();i++){
  31.         if(sys[i].a == a && sys[i].t<mint){
  32.             mint = sys[i].t;
  33.             num = sys[i].b;
  34.         }
  35.     }
  36.     temp x = {num,mint};
  37.     return x;
  38. }
  39. int main(){
  40.     int t;
  41.     cin >> t;
  42.     vector< vector<int> >answers(t);
  43.  
  44.     for(int i = 0;i<t;i++){
  45.         int n,d,c;
  46.         cin >> n >> d >> c;
  47.         vector<sub> sys(d);
  48.         for(int j = 0;j<d;j++){
  49.             int a,b,t;
  50.             cin >> a >> b >> t;
  51.             sys.push_back({a,b,t});
  52.         }
  53.         bool goingwrong = true;
  54.         temp p = findb(c,sys);
  55.         int alltime = p.time;
  56.         int num = p.num;
  57.         int amount = 1;
  58.         bool nowa = true;
  59.         while(goingwrong){
  60.             if(nowa){
  61.                 temp tp = finda(num,sys);
  62.                 if(tp.num==-1){
  63.                     answers[i][0] = amount;
  64.                     answers[i][1] = alltime;
  65.                     goingwrong = false;
  66.                 }else{
  67.                     amount++;
  68.                     alltime += tp.time;
  69.                     sys.erase(sys.begin()+tp.num);
  70.                 }
  71.                 nowa = false;
  72.             }else{
  73.                 temp tp = findb(num,sys);
  74.                 if(tp.num==-1){
  75.                     answers[i][0] = amount;
  76.                     answers[i][1] = alltime;
  77.                     goingwrong = false;
  78.                 }else{
  79.                     amount++;
  80.                     alltime += tp.time;
  81.                     sys.erase(sys.begin()+tp.num);
  82.                 }
  83.                 nowa = true;
  84.             }
  85.         }
  86.     }
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement