답안 #590446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590446 2022-07-06T00:03:47 Z APROHACK 꿈 (IOI13_dreaming) C++14
47 / 100
73 ms 19140 KB
#include <bits/stdc++.h>
#include "dreaming.h"
#define ll long long
#define PB push_back
#define F first
#define S second
using namespace std;
const ll MAXN = 100001;
bool recorrido[MAXN];
vector<pair<int, ll > >adj[MAXN];
vector<int>camino;
ll maxtraveltime = 0, nodox;
bool two = false;
ll findlongest(int node, ll cur, int parent){
   // cout<<node<<endl;
    recorrido[node]=true;
    int pp = 0;
    for(int i = 0 ;i  < adj[node].size(); i++){
        if(parent != adj[node][i].F){
            if(findlongest(adj[node][i].F, cur+adj[node][i].S, node)){
                camino.PB(node);
                //cout<<"added "<<node<<" "<<endl;
                if(two)pp++;
            }
        }
    }
    if(pp)return pp;
    if(cur>maxtraveltime){
        maxtraveltime=cur;
        nodox=node;
        camino.PB(node);
        //cout<<node<<" "; 
        return 1;
    }
    return 0;
}
ll centro, dist1, dist2, diff;
ll findCentro(int node, int lleva){
    //cout<<node<<" "<<lleva<<" "<<maxtraveltime-lleva<<endl;
    if(llabs((maxtraveltime-lleva) - lleva)<diff){
        centro = node;
        diff=abs(lleva - (maxtraveltime-lleva));
        dist1=lleva;
        dist2=maxtraveltime-lleva;
        
    }
    if(lleva > (maxtraveltime-lleva)){
        return centro;
    }
    
    
    for(int i = 0 ;i  < adj[node].size(); i++){
        if(camino.back() == adj[node][i].F){
            camino.pop_back();
            return findCentro(adj[node][i].F, adj[node][i].S+lleva);
        }
    }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i = 0 ; i < M ; i ++){
        adj[A[i]].PB({B[i], T[i]});
        adj[B[i]].PB({A[i], T[i]});
    }
    vector<pair<pair<ll, ll>, int> >arboles; //distA distB Centro
    for(int i = 0 ; i < N ; i++){
        if(!recorrido[i]){
            //cout<<"runnin"<<i<<endl;


            maxtraveltime=0;
            two=false;
            diff=LLONG_MAX;
            if(adj[i].size()==0){
                arboles.PB({{0, 0}, i});
                //cout<<"cc"<<0<<" "<<0<<" "<<i<<endl;
                continue;
            }
            findlongest(i, 0, -1);
            ll A = nodox;

            maxtraveltime = 0;
            two=true;
            findlongest(A, 0, -1);
            ll B = nodox;
            ////cout<<"mx"<<maxtraveltime<<endl;
            camino.pop_back();
            ll C = findCentro(A, 0);
            
            arboles.PB({{dist1, dist2}, centro});
            //cout<<"cc"<<dist1<<" "<<dist2<<" "<<centro<<endl;
        }
    }
    ll centro1=arboles[0].S, distA=arboles[0].F.F, distB=arboles[0].F.S;
    for(int i = 1 ; i < arboles.size() ; i++){
        //cout<<centro1<<" "<<distA<<" "<<distB<<endl;
        ll unir = L+max(distA, distB)+max(arboles[i].F.F, arboles[i].F.S);
        ll ncentro = max(distA, distB)>max(arboles[i].F.F, arboles[i].F.S) ? centro1 : arboles[i].S;
        if(max(distA+distB, arboles[i].F.F+arboles[i].F.S)>unir){
            if((distA+distB>arboles[i].F.F+arboles[i].F.S)){
                //no hay cambio
            }else{
                centro1=arboles[i].S;
                distA=arboles[i].F.F;
                distB=arboles[i].F.S;
            }
        }else{
            if(max(distA, distB)>max(arboles[i].F.F, arboles[i].F.S)){
                if(distA<distB)swap(distA, distB);
                distB=L+max(arboles[i].F.F, arboles[i].F.S);
            }else{
                if(distA<distB)swap(distA, distB);
                distA+=L;
                distB=max(arboles[i].F.F, arboles[i].F.S);
            }
            centro1=ncentro;
        }
        
    }
    //cout<<centro1<<" "<<distA<<" "<<distB<<endl;
    return distA+distB;
}
/*
int main(){
    ll n, m, a, b   , t, tt;
    cin>>n>>m>>tt;
    vector<int>A, B, T;
    for(int i = 0 ; i < m ; i++){
        cin>>a>>b>>t;
        A.PB(a);
        B.PB(b);
        T.PB(t);
    }
    cout<<travelTime(n, m, tt, A.data(), B.data(), T.data())<<endl;
}
*/

Compilation message

dreaming.cpp: In function 'long long int findlongest(int, long long int, int)':
dreaming.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i = 0 ;i  < adj[node].size(); i++){
      |                    ~~~^~~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'long long int findCentro(int, int)':
dreaming.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i = 0 ;i  < adj[node].size(); i++){
      |                    ~~~^~~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:84:16: warning: unused variable 'B' [-Wunused-variable]
   84 |             ll B = nodox;
      |                ^
dreaming.cpp:87:16: warning: unused variable 'C' [-Wunused-variable]
   87 |             ll C = findCentro(A, 0);
      |                ^
dreaming.cpp:94:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for(int i = 1 ; i < arboles.size() ; i++){
      |                     ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'long long int findCentro(int, int)':
dreaming.cpp:58:1: warning: control reaches end of non-void function [-Wreturn-type]
   58 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 17092 KB Output is correct
2 Correct 43 ms 16956 KB Output is correct
3 Correct 29 ms 12216 KB Output is correct
4 Correct 8 ms 4740 KB Output is correct
5 Correct 6 ms 3924 KB Output is correct
6 Correct 12 ms 5984 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 22 ms 7852 KB Output is correct
9 Correct 30 ms 10032 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 43 ms 12364 KB Output is correct
12 Correct 54 ms 14876 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2660 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 1 ms 2660 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 1 ms 2664 KB Output is correct
21 Correct 2 ms 2668 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 17092 KB Output is correct
2 Correct 43 ms 16956 KB Output is correct
3 Correct 29 ms 12216 KB Output is correct
4 Correct 8 ms 4740 KB Output is correct
5 Correct 6 ms 3924 KB Output is correct
6 Correct 12 ms 5984 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 22 ms 7852 KB Output is correct
9 Correct 30 ms 10032 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 43 ms 12364 KB Output is correct
12 Correct 54 ms 14876 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2668 KB Output is correct
18 Correct 2 ms 2660 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 1 ms 2660 KB Output is correct
32 Correct 2 ms 2668 KB Output is correct
33 Correct 1 ms 2664 KB Output is correct
34 Correct 2 ms 2668 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 43 ms 17080 KB Output is correct
40 Correct 43 ms 17028 KB Output is correct
41 Correct 29 ms 12200 KB Output is correct
42 Correct 7 ms 4820 KB Output is correct
43 Correct 2 ms 2660 KB Output is correct
44 Correct 1 ms 2660 KB Output is correct
45 Correct 2 ms 2772 KB Output is correct
46 Correct 2 ms 2664 KB Output is correct
47 Correct 1 ms 2668 KB Output is correct
48 Correct 2 ms 2664 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 1 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 1 ms 2644 KB Output is correct
54 Correct 1 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 1 ms 2644 KB Output is correct
57 Correct 58 ms 11152 KB Output is correct
58 Correct 56 ms 11152 KB Output is correct
59 Correct 57 ms 10956 KB Output is correct
60 Correct 57 ms 10928 KB Output is correct
61 Correct 55 ms 10804 KB Output is correct
62 Correct 52 ms 10832 KB Output is correct
63 Correct 51 ms 10316 KB Output is correct
64 Correct 49 ms 10416 KB Output is correct
65 Correct 53 ms 10628 KB Output is correct
66 Correct 50 ms 10668 KB Output is correct
67 Correct 59 ms 10956 KB Output is correct
68 Correct 59 ms 11000 KB Output is correct
69 Correct 57 ms 11340 KB Output is correct
70 Correct 56 ms 11204 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 3 ms 3052 KB Output is correct
73 Correct 3 ms 2900 KB Output is correct
74 Correct 2 ms 2800 KB Output is correct
75 Correct 3 ms 2804 KB Output is correct
76 Correct 4 ms 2900 KB Output is correct
77 Correct 3 ms 2900 KB Output is correct
78 Correct 3 ms 2928 KB Output is correct
79 Correct 3 ms 2900 KB Output is correct
80 Correct 63 ms 10916 KB Output is correct
81 Correct 57 ms 10956 KB Output is correct
82 Correct 53 ms 10816 KB Output is correct
83 Correct 54 ms 10856 KB Output is correct
84 Correct 2 ms 2772 KB Output is correct
85 Correct 2 ms 2808 KB Output is correct
86 Correct 2 ms 2772 KB Output is correct
87 Correct 3 ms 2800 KB Output is correct
88 Correct 3 ms 2804 KB Output is correct
89 Correct 3 ms 2800 KB Output is correct
90 Correct 3 ms 2772 KB Output is correct
91 Correct 3 ms 2900 KB Output is correct
92 Correct 2 ms 2772 KB Output is correct
93 Correct 3 ms 2900 KB Output is correct
94 Correct 1 ms 2644 KB Output is correct
95 Correct 2 ms 2644 KB Output is correct
96 Correct 1 ms 2644 KB Output is correct
97 Correct 1 ms 2644 KB Output is correct
98 Correct 1 ms 2644 KB Output is correct
99 Correct 2 ms 2644 KB Output is correct
100 Correct 1 ms 2644 KB Output is correct
101 Correct 2 ms 2644 KB Output is correct
102 Correct 2 ms 2660 KB Output is correct
103 Correct 2 ms 2644 KB Output is correct
104 Correct 6 ms 3924 KB Output is correct
105 Correct 11 ms 6004 KB Output is correct
106 Correct 2 ms 2644 KB Output is correct
107 Correct 22 ms 7884 KB Output is correct
108 Correct 31 ms 10060 KB Output is correct
109 Correct 2 ms 2772 KB Output is correct
110 Correct 46 ms 12360 KB Output is correct
111 Correct 52 ms 14860 KB Output is correct
112 Correct 2 ms 2772 KB Output is correct
113 Correct 73 ms 19140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 7436 KB Output is correct
2 Incorrect 19 ms 7488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2660 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 1 ms 2660 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 1 ms 2664 KB Output is correct
21 Correct 2 ms 2668 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 3 ms 2900 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 3 ms 2772 KB Output is correct
31 Correct 2 ms 2900 KB Output is correct
32 Correct 2 ms 2672 KB Output is correct
33 Incorrect 2 ms 2736 KB Output isn't correct
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 17092 KB Output is correct
2 Correct 43 ms 16956 KB Output is correct
3 Correct 29 ms 12216 KB Output is correct
4 Correct 8 ms 4740 KB Output is correct
5 Correct 6 ms 3924 KB Output is correct
6 Correct 12 ms 5984 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 22 ms 7852 KB Output is correct
9 Correct 30 ms 10032 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 43 ms 12364 KB Output is correct
12 Correct 54 ms 14876 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2668 KB Output is correct
18 Correct 2 ms 2660 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 1 ms 2660 KB Output is correct
32 Correct 2 ms 2668 KB Output is correct
33 Correct 1 ms 2664 KB Output is correct
34 Correct 2 ms 2668 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 43 ms 17080 KB Output is correct
40 Correct 43 ms 17028 KB Output is correct
41 Correct 29 ms 12200 KB Output is correct
42 Correct 7 ms 4820 KB Output is correct
43 Correct 2 ms 2660 KB Output is correct
44 Correct 1 ms 2660 KB Output is correct
45 Correct 2 ms 2772 KB Output is correct
46 Correct 2 ms 2664 KB Output is correct
47 Correct 1 ms 2668 KB Output is correct
48 Correct 2 ms 2664 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 1 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 1 ms 2644 KB Output is correct
54 Correct 1 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 1 ms 2644 KB Output is correct
57 Correct 58 ms 11152 KB Output is correct
58 Correct 56 ms 11152 KB Output is correct
59 Correct 57 ms 10956 KB Output is correct
60 Correct 57 ms 10928 KB Output is correct
61 Correct 55 ms 10804 KB Output is correct
62 Correct 52 ms 10832 KB Output is correct
63 Correct 51 ms 10316 KB Output is correct
64 Correct 49 ms 10416 KB Output is correct
65 Correct 53 ms 10628 KB Output is correct
66 Correct 50 ms 10668 KB Output is correct
67 Correct 59 ms 10956 KB Output is correct
68 Correct 59 ms 11000 KB Output is correct
69 Correct 57 ms 11340 KB Output is correct
70 Correct 56 ms 11204 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 3 ms 3052 KB Output is correct
73 Correct 3 ms 2900 KB Output is correct
74 Correct 2 ms 2800 KB Output is correct
75 Correct 3 ms 2804 KB Output is correct
76 Correct 4 ms 2900 KB Output is correct
77 Correct 3 ms 2900 KB Output is correct
78 Correct 3 ms 2928 KB Output is correct
79 Correct 3 ms 2900 KB Output is correct
80 Correct 63 ms 10916 KB Output is correct
81 Correct 57 ms 10956 KB Output is correct
82 Correct 53 ms 10816 KB Output is correct
83 Correct 54 ms 10856 KB Output is correct
84 Correct 2 ms 2772 KB Output is correct
85 Correct 2 ms 2808 KB Output is correct
86 Correct 2 ms 2772 KB Output is correct
87 Correct 3 ms 2800 KB Output is correct
88 Correct 3 ms 2804 KB Output is correct
89 Correct 3 ms 2800 KB Output is correct
90 Correct 3 ms 2772 KB Output is correct
91 Correct 3 ms 2900 KB Output is correct
92 Correct 2 ms 2772 KB Output is correct
93 Correct 3 ms 2900 KB Output is correct
94 Correct 1 ms 2644 KB Output is correct
95 Correct 2 ms 2644 KB Output is correct
96 Correct 1 ms 2644 KB Output is correct
97 Correct 1 ms 2644 KB Output is correct
98 Correct 1 ms 2644 KB Output is correct
99 Correct 2 ms 2644 KB Output is correct
100 Correct 1 ms 2644 KB Output is correct
101 Correct 2 ms 2644 KB Output is correct
102 Correct 2 ms 2660 KB Output is correct
103 Correct 2 ms 2644 KB Output is correct
104 Correct 6 ms 3924 KB Output is correct
105 Correct 11 ms 6004 KB Output is correct
106 Correct 2 ms 2644 KB Output is correct
107 Correct 22 ms 7884 KB Output is correct
108 Correct 31 ms 10060 KB Output is correct
109 Correct 2 ms 2772 KB Output is correct
110 Correct 46 ms 12360 KB Output is correct
111 Correct 52 ms 14860 KB Output is correct
112 Correct 2 ms 2772 KB Output is correct
113 Correct 73 ms 19140 KB Output is correct
114 Correct 16 ms 7436 KB Output is correct
115 Incorrect 19 ms 7488 KB Output isn't correct
116 Halted 0 ms 0 KB -