답안 #530458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530458 2022-02-25T12:08:17 Z __Variatto 꿈 (IOI13_dreaming) C++17
47 / 100
78 ms 15704 KB
#include <bits/stdc++.h>
#include"dreaming.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=1e5+10, MAXV=1e9+10;
int n, m, l, odl[MAX][2];
vector<pair<int,int>>g[MAX];
pair<int,int>maxi;
bool odw[MAX];
void dfso(int v, int oj, int x, int nr){
    odl[v][nr]=x;
    odw[v]=true;
    maxi=max(maxi, {x, v});
    for(auto s: g[v])
        if(s.fi!=oj)
            dfso(s.fi, v, x+s.se, nr);
}
pair<int,int>mini;
void dfs(int v, int oj){
    mini=min(mini, {max(odl[v][0], odl[v][1]), v});
    for(auto s: g[v])
        if(s.fi!=oj)
            dfs(s.fi,v);
}
int travelTime(int N, int M, int L, int a[], int b[], int t[]){
    n=N, m=M, l=L;
    for(int i=0; i<m; i++)
        g[a[i]].pb({b[i], t[i]}), g[b[i]].pb({a[i], t[i]});
    int ls1=-1, ls2=-1, lmid=-1, dl=0, lmids1=0, lmids2=0;
    for(int i=0; i<n; i++){
        if(odw[i])
            continue;
        maxi={0,0};
        dfso(i, i, 0, 0);
        int s1=maxi.se;
        maxi={0,0};
        dfso(s1, s1, 0, 0);
        int s2=maxi.se;
        maxi={0,0};
        dfso(s2, s2, 0, 1);
        mini={MAXV,0};
        dfs(i, i);
        int mid=mini.se;
        int mids1=odl[mid][0], mids2=odl[mid][1];
        if(ls1==-1){
            ls1=s1, ls2=s2, lmid=mid, dl=odl[s2][0], lmids1=mids1, lmids2=mids2;
            continue;
        }
        if(dl<max(mids1, mids2)+max(lmids1, lmids2)+l){
            dl=max(mids1, mids2)+max(lmids1, lmids2)+l;
            int nmid, ns1, ns2, nmids1, nmids2;
            if(mids1>mids2 && lmids1>lmids2){
                ns1=s1, ns2=ls1;
                if(max(mids1, lmids1+l)<max(lmids1, mids1+l))
                    nmid=mid, nmids1=mids1, nmids2=lmids1+l;
                else
                    nmid=lmid, nmids1=mids1+l, nmids2=lmids1;
            }
            if(mids1>mids2 && lmids2>lmids1){
                ns1=s1, ns2=ls2;
                if(max(mids1, lmids2+l)<max(lmids2, mids1+l))
                    nmid=mid, nmids1=mids1, nmids2=lmids2+l;
                else
                    nmid=lmid, nmids1=mids1+l, nmids2=lmids2;
            }
            if(mids2>mids1 && lmids1>lmids2){
                ns1=s2, ns2=ls1;
                if(max(mids2, lmids1+l)<max(lmids1, mids2+l))
                    nmid=mid, nmids1=mids2, nmids2=lmids1+l;
                else
                    nmid=lmid, nmids1=mids2+l, nmids2=lmids1;
            }
            if(mids2>mids1 && lmids2>lmids1){
                ns1=s2, ns2=ls2;
                if(max(mids2, lmids2+l)<max(lmids2, mids2+l))
                    nmid=mid, nmids1=mids2, nmids2=lmids2+l;
                else
                    nmid=lmid, nmids1=mids2+l, nmids2=lmids2;
            }
            lmid=nmid, lmids1=nmids1, lmids2=nmids2, ls1=ns1, ls2=ns2;
        }
        if(dl<odl[s2][0])
            ls1=s1, ls2=s2, lmid=mid, dl=odl[s2][0], lmids1=mids1, lmids2=mids2;
        ///cout<<ls1<<" "<<ls2<<" "<<dl<<" "<<lmids1<<" "<<lmids2<<"\n";

    }
    return dl;
}
/*int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int N, M, L;
    cin>>N>>M>>L;
    int A[M+2], B[M+2], T[M+2];
    for(int i=0; i<M; i++)
        cin>>A[i]>>B[i]>>T[i];
    cout<<travelTime(N, M, L, A, B, T)<<"\n";

}
*/

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:32:50: warning: 'lmids2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |     int ls1=-1, ls2=-1, lmid=-1, dl=0, lmids1=0, lmids2=0;
      |                                                  ^~~~~~
dreaming.cpp:62:28: warning: 'lmids1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |             if(mids1>mids2 && lmids2>lmids1){
      |                ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
dreaming.cpp:48:9: warning: 'ls1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |         if(ls1==-1){
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 13324 KB Output is correct
2 Correct 45 ms 13216 KB Output is correct
3 Correct 29 ms 9804 KB Output is correct
4 Correct 7 ms 4300 KB Output is correct
5 Correct 6 ms 3560 KB Output is correct
6 Correct 12 ms 5212 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 22 ms 6756 KB Output is correct
9 Correct 27 ms 8356 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 58 ms 10496 KB Output is correct
12 Correct 53 ms 12216 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2660 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 1 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 1 ms 2636 KB Output is correct
11 Correct 2 ms 2660 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 1 ms 2636 KB Output is correct
17 Correct 2 ms 2656 KB Output is correct
18 Correct 2 ms 2656 KB Output is correct
19 Correct 1 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 1 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 13324 KB Output is correct
2 Correct 45 ms 13216 KB Output is correct
3 Correct 29 ms 9804 KB Output is correct
4 Correct 7 ms 4300 KB Output is correct
5 Correct 6 ms 3560 KB Output is correct
6 Correct 12 ms 5212 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 22 ms 6756 KB Output is correct
9 Correct 27 ms 8356 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 58 ms 10496 KB Output is correct
12 Correct 53 ms 12216 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 2 ms 2660 KB Output is correct
15 Correct 1 ms 2636 KB Output is correct
16 Correct 1 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 1 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 1 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 1 ms 2636 KB Output is correct
24 Correct 2 ms 2660 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 2 ms 2648 KB Output is correct
27 Correct 2 ms 2636 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 1 ms 2636 KB Output is correct
30 Correct 2 ms 2656 KB Output is correct
31 Correct 2 ms 2656 KB Output is correct
32 Correct 1 ms 2636 KB Output is correct
33 Correct 2 ms 2636 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 1 ms 2636 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 2 ms 2636 KB Output is correct
39 Correct 44 ms 14304 KB Output is correct
40 Correct 46 ms 14288 KB Output is correct
41 Correct 29 ms 10368 KB Output is correct
42 Correct 7 ms 4376 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 1 ms 2656 KB Output is correct
45 Correct 2 ms 2636 KB Output is correct
46 Correct 1 ms 2636 KB Output is correct
47 Correct 1 ms 2636 KB Output is correct
48 Correct 2 ms 2656 KB Output is correct
49 Correct 1 ms 2636 KB Output is correct
50 Correct 1 ms 2636 KB Output is correct
51 Correct 2 ms 2636 KB Output is correct
52 Correct 1 ms 2636 KB Output is correct
53 Correct 2 ms 2636 KB Output is correct
54 Correct 2 ms 2636 KB Output is correct
55 Correct 2 ms 2636 KB Output is correct
56 Correct 2 ms 2652 KB Output is correct
57 Correct 63 ms 9924 KB Output is correct
58 Correct 63 ms 9924 KB Output is correct
59 Correct 61 ms 9924 KB Output is correct
60 Correct 60 ms 9896 KB Output is correct
61 Correct 60 ms 10092 KB Output is correct
62 Correct 59 ms 10048 KB Output is correct
63 Correct 54 ms 9716 KB Output is correct
64 Correct 54 ms 9652 KB Output is correct
65 Correct 56 ms 9904 KB Output is correct
66 Correct 55 ms 9932 KB Output is correct
67 Correct 63 ms 9864 KB Output is correct
68 Correct 62 ms 9960 KB Output is correct
69 Correct 62 ms 10264 KB Output is correct
70 Correct 60 ms 10220 KB Output is correct
71 Correct 1 ms 2636 KB Output is correct
72 Correct 3 ms 2764 KB Output is correct
73 Correct 3 ms 2892 KB Output is correct
74 Correct 3 ms 2892 KB Output is correct
75 Correct 3 ms 2764 KB Output is correct
76 Correct 3 ms 2764 KB Output is correct
77 Correct 2 ms 2764 KB Output is correct
78 Correct 3 ms 2892 KB Output is correct
79 Correct 3 ms 2892 KB Output is correct
80 Correct 61 ms 9904 KB Output is correct
81 Correct 62 ms 9924 KB Output is correct
82 Correct 60 ms 10044 KB Output is correct
83 Correct 65 ms 10060 KB Output is correct
84 Correct 2 ms 2764 KB Output is correct
85 Correct 2 ms 2764 KB Output is correct
86 Correct 3 ms 2824 KB Output is correct
87 Correct 2 ms 2764 KB Output is correct
88 Correct 3 ms 2796 KB Output is correct
89 Correct 3 ms 2800 KB Output is correct
90 Correct 3 ms 2832 KB Output is correct
91 Correct 3 ms 2764 KB Output is correct
92 Correct 3 ms 2764 KB Output is correct
93 Correct 2 ms 2764 KB Output is correct
94 Correct 1 ms 2636 KB Output is correct
95 Correct 1 ms 2640 KB Output is correct
96 Correct 2 ms 2640 KB Output is correct
97 Correct 1 ms 2680 KB Output is correct
98 Correct 2 ms 2656 KB Output is correct
99 Correct 2 ms 2636 KB Output is correct
100 Correct 1 ms 2636 KB Output is correct
101 Correct 1 ms 2640 KB Output is correct
102 Correct 2 ms 2636 KB Output is correct
103 Correct 2 ms 2636 KB Output is correct
104 Correct 6 ms 3600 KB Output is correct
105 Correct 11 ms 5316 KB Output is correct
106 Correct 2 ms 2636 KB Output is correct
107 Correct 21 ms 6640 KB Output is correct
108 Correct 28 ms 8404 KB Output is correct
109 Correct 2 ms 2636 KB Output is correct
110 Correct 41 ms 10340 KB Output is correct
111 Correct 58 ms 12228 KB Output is correct
112 Correct 2 ms 2636 KB Output is correct
113 Correct 78 ms 15704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 5956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2660 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 1 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 1 ms 2636 KB Output is correct
11 Correct 2 ms 2660 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 1 ms 2636 KB Output is correct
17 Correct 2 ms 2656 KB Output is correct
18 Correct 2 ms 2656 KB Output is correct
19 Correct 1 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 1 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 2 ms 2636 KB Output is correct
27 Correct 2 ms 2764 KB Output is correct
28 Correct 3 ms 2764 KB Output is correct
29 Correct 2 ms 2636 KB Output is correct
30 Correct 2 ms 2796 KB Output is correct
31 Correct 3 ms 2764 KB Output is correct
32 Incorrect 2 ms 2660 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 13324 KB Output is correct
2 Correct 45 ms 13216 KB Output is correct
3 Correct 29 ms 9804 KB Output is correct
4 Correct 7 ms 4300 KB Output is correct
5 Correct 6 ms 3560 KB Output is correct
6 Correct 12 ms 5212 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 22 ms 6756 KB Output is correct
9 Correct 27 ms 8356 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 58 ms 10496 KB Output is correct
12 Correct 53 ms 12216 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 2 ms 2660 KB Output is correct
15 Correct 1 ms 2636 KB Output is correct
16 Correct 1 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 1 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 1 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 1 ms 2636 KB Output is correct
24 Correct 2 ms 2660 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 2 ms 2648 KB Output is correct
27 Correct 2 ms 2636 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 1 ms 2636 KB Output is correct
30 Correct 2 ms 2656 KB Output is correct
31 Correct 2 ms 2656 KB Output is correct
32 Correct 1 ms 2636 KB Output is correct
33 Correct 2 ms 2636 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 1 ms 2636 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 2 ms 2636 KB Output is correct
39 Correct 44 ms 14304 KB Output is correct
40 Correct 46 ms 14288 KB Output is correct
41 Correct 29 ms 10368 KB Output is correct
42 Correct 7 ms 4376 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 1 ms 2656 KB Output is correct
45 Correct 2 ms 2636 KB Output is correct
46 Correct 1 ms 2636 KB Output is correct
47 Correct 1 ms 2636 KB Output is correct
48 Correct 2 ms 2656 KB Output is correct
49 Correct 1 ms 2636 KB Output is correct
50 Correct 1 ms 2636 KB Output is correct
51 Correct 2 ms 2636 KB Output is correct
52 Correct 1 ms 2636 KB Output is correct
53 Correct 2 ms 2636 KB Output is correct
54 Correct 2 ms 2636 KB Output is correct
55 Correct 2 ms 2636 KB Output is correct
56 Correct 2 ms 2652 KB Output is correct
57 Correct 63 ms 9924 KB Output is correct
58 Correct 63 ms 9924 KB Output is correct
59 Correct 61 ms 9924 KB Output is correct
60 Correct 60 ms 9896 KB Output is correct
61 Correct 60 ms 10092 KB Output is correct
62 Correct 59 ms 10048 KB Output is correct
63 Correct 54 ms 9716 KB Output is correct
64 Correct 54 ms 9652 KB Output is correct
65 Correct 56 ms 9904 KB Output is correct
66 Correct 55 ms 9932 KB Output is correct
67 Correct 63 ms 9864 KB Output is correct
68 Correct 62 ms 9960 KB Output is correct
69 Correct 62 ms 10264 KB Output is correct
70 Correct 60 ms 10220 KB Output is correct
71 Correct 1 ms 2636 KB Output is correct
72 Correct 3 ms 2764 KB Output is correct
73 Correct 3 ms 2892 KB Output is correct
74 Correct 3 ms 2892 KB Output is correct
75 Correct 3 ms 2764 KB Output is correct
76 Correct 3 ms 2764 KB Output is correct
77 Correct 2 ms 2764 KB Output is correct
78 Correct 3 ms 2892 KB Output is correct
79 Correct 3 ms 2892 KB Output is correct
80 Correct 61 ms 9904 KB Output is correct
81 Correct 62 ms 9924 KB Output is correct
82 Correct 60 ms 10044 KB Output is correct
83 Correct 65 ms 10060 KB Output is correct
84 Correct 2 ms 2764 KB Output is correct
85 Correct 2 ms 2764 KB Output is correct
86 Correct 3 ms 2824 KB Output is correct
87 Correct 2 ms 2764 KB Output is correct
88 Correct 3 ms 2796 KB Output is correct
89 Correct 3 ms 2800 KB Output is correct
90 Correct 3 ms 2832 KB Output is correct
91 Correct 3 ms 2764 KB Output is correct
92 Correct 3 ms 2764 KB Output is correct
93 Correct 2 ms 2764 KB Output is correct
94 Correct 1 ms 2636 KB Output is correct
95 Correct 1 ms 2640 KB Output is correct
96 Correct 2 ms 2640 KB Output is correct
97 Correct 1 ms 2680 KB Output is correct
98 Correct 2 ms 2656 KB Output is correct
99 Correct 2 ms 2636 KB Output is correct
100 Correct 1 ms 2636 KB Output is correct
101 Correct 1 ms 2640 KB Output is correct
102 Correct 2 ms 2636 KB Output is correct
103 Correct 2 ms 2636 KB Output is correct
104 Correct 6 ms 3600 KB Output is correct
105 Correct 11 ms 5316 KB Output is correct
106 Correct 2 ms 2636 KB Output is correct
107 Correct 21 ms 6640 KB Output is correct
108 Correct 28 ms 8404 KB Output is correct
109 Correct 2 ms 2636 KB Output is correct
110 Correct 41 ms 10340 KB Output is correct
111 Correct 58 ms 12228 KB Output is correct
112 Correct 2 ms 2636 KB Output is correct
113 Correct 78 ms 15704 KB Output is correct
114 Incorrect 17 ms 5956 KB Output isn't correct
115 Halted 0 ms 0 KB -