Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<algorithm>
- using namespace std;
- struct sub{
- int a=0;
- int b=0;
- int t= 0;
- };
- struct temp{
- int num,time;
- };
- temp finda(int b, vector<sub> sys){
- int mint = 1005;
- int num = -1;
- for(int i =0;i<sys.size();i++){
- if(sys[i].b == b && sys[i].t<mint){
- mint = sys[i].t;
- num = sys[i].a;
- }
- }
- temp x = {num,mint};
- return x;
- }
- temp findb(int a, vector<sub> sys){
- int mint = 1005;
- int num = -1;
- for(int i =0;i<sys.size();i++){
- if(sys[i].a == a && sys[i].t<mint){
- mint = sys[i].t;
- num = sys[i].b;
- }
- }
- temp x = {num,mint};
- return x;
- }
- int main(){
- int t;
- cin >> t;
- vector< vector<int> >answers(t);
- for(int i = 0;i<t;i++){
- int n,d,c;
- cin >> n >> d >> c;
- vector<sub> sys(d);
- for(int j = 0;j<d;j++){
- int a,b,t;
- cin >> a >> b >> t;
- sys.push_back({a,b,t});
- }
- bool goingwrong = true;
- temp p = findb(c,sys);
- int alltime = p.time;
- int num = p.num;
- int amount = 1;
- bool nowa = true;
- while(goingwrong){
- if(nowa){
- temp tp = finda(num,sys);
- if(tp.num==-1){
- answers[i][0] = amount;
- answers[i][1] = alltime;
- goingwrong = false;
- }else{
- amount++;
- alltime += tp.time;
- sys.erase(sys.begin()+tp.num);
- }
- nowa = false;
- }else{
- temp tp = findb(num,sys);
- if(tp.num==-1){
- answers[i][0] = amount;
- answers[i][1] = alltime;
- goingwrong = false;
- }else{
- amount++;
- alltime += tp.time;
- sys.erase(sys.begin()+tp.num);
- }
- nowa = true;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement