# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
400261 |
2021-05-07T19:02:35 Z |
peuch |
Dreaming (IOI13_dreaming) |
C++17 |
|
96 ms |
21592 KB |
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const int MAXN = 1e5 + 10;
int marc[MAXN], dist[MAXN], longDist[2][MAXN];
int aux;
vector<int> ar[MAXN];
vector<int> wg[MAXN];
vector<int> group;
int dfs1(int cur);
int dfs2(int cur);
int dfs3(int cur);
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i = 0; i < M; i++){
ar[A[i]].push_back(B[i]);
ar[B[i]].push_back(A[i]);
wg[A[i]].push_back(T[i]);
wg[B[i]].push_back(T[i]);
}
int ret = 0;
for(int i = 0; i < N; i++){
if(marc[i] == 3) continue;
dist[i] = 0;
aux = 0;
int side1 = dfs1(i);
longDist[0][side1] = 0;
int side2 = dfs2(side1);
ret = max(ret, longDist[0][side2]);
// printf("group: %d ends = %d and %d with %d nodes\n", group.size(), side1, side2, aux);
longDist[1][side2] = 0;
group.push_back(dfs3(side2));
}
sort(group.begin(), group.end());
reverse(group.begin(), group.end());
ret = max(ret, max(group[0] + group[1] + L, group[1] + group[2] + 2 * L));
return ret;
}
int dfs1(int cur){
marc[cur] = 1;
aux++;
int ret = cur;
int auxRet = dist[cur];
for(int i = 0; i < ar[cur].size(); i++){
int viz = ar[cur][i];
int len = wg[cur][i];
if(marc[viz] == 1) continue;
dist[viz] = dist[cur] + len;
int dfsVal = dfs1(viz);
if(dist[dfsVal] > auxRet) ret = dfsVal, auxRet = dist[dfsVal];
}
return ret;
}
int dfs2(int cur){
marc[cur] = 2;
int ret = cur;
int auxRet = longDist[0][cur];
for(int i = 0; i < ar[cur].size(); i++){
int viz = ar[cur][i];
int len = wg[cur][i];
if(marc[viz] == 2) continue;
longDist[0][viz] = longDist[0][cur] + len;
int dfsVal = dfs2(viz);
if(longDist[0][dfsVal] > auxRet) ret = dfsVal, auxRet = longDist[0][dfsVal];
}
return ret;
}
int dfs3(int cur){
marc[cur] = 3;
int ret = max(longDist[0][cur], longDist[1][cur]);
for(int i = 0; i < ar[cur].size(); i++){
int viz = ar[cur][i];
int len = wg[cur][i];
if(marc[viz] == 3) continue;
longDist[1][viz] = longDist[1][cur] + len;
ret = min(ret, dfs3(viz));
}
// printf("%d max(%d %d) -> %d\n", cur, longDist[0][cur], longDist[1][cur], ret);
return ret;
}
Compilation message
dreaming.cpp: In function 'int dfs1(int)':
dreaming.cpp:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i = 0; i < ar[cur].size(); i++){
| ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs2(int)':
dreaming.cpp:64:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i = 0; i < ar[cur].size(); i++){
| ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs3(int)':
dreaming.cpp:78:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i = 0; i < ar[cur].size(); i++){
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
21592 KB |
Output is correct |
2 |
Correct |
80 ms |
21468 KB |
Output is correct |
3 |
Correct |
49 ms |
15932 KB |
Output is correct |
4 |
Correct |
12 ms |
7372 KB |
Output is correct |
5 |
Correct |
11 ms |
6400 KB |
Output is correct |
6 |
Correct |
24 ms |
8652 KB |
Output is correct |
7 |
Incorrect |
4 ms |
5068 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4940 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
21592 KB |
Output is correct |
2 |
Correct |
80 ms |
21468 KB |
Output is correct |
3 |
Correct |
49 ms |
15932 KB |
Output is correct |
4 |
Correct |
12 ms |
7372 KB |
Output is correct |
5 |
Correct |
11 ms |
6400 KB |
Output is correct |
6 |
Correct |
24 ms |
8652 KB |
Output is correct |
7 |
Incorrect |
4 ms |
5068 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
11436 KB |
Output is correct |
2 |
Correct |
36 ms |
11592 KB |
Output is correct |
3 |
Correct |
35 ms |
11460 KB |
Output is correct |
4 |
Correct |
35 ms |
11588 KB |
Output is correct |
5 |
Correct |
47 ms |
11464 KB |
Output is correct |
6 |
Correct |
49 ms |
12140 KB |
Output is correct |
7 |
Correct |
42 ms |
11832 KB |
Output is correct |
8 |
Correct |
35 ms |
11468 KB |
Output is correct |
9 |
Correct |
34 ms |
11372 KB |
Output is correct |
10 |
Correct |
37 ms |
11676 KB |
Output is correct |
11 |
Correct |
3 ms |
5008 KB |
Output is correct |
12 |
Correct |
8 ms |
7184 KB |
Output is correct |
13 |
Correct |
8 ms |
7252 KB |
Output is correct |
14 |
Correct |
8 ms |
7116 KB |
Output is correct |
15 |
Correct |
9 ms |
7240 KB |
Output is correct |
16 |
Correct |
9 ms |
7240 KB |
Output is correct |
17 |
Correct |
8 ms |
7108 KB |
Output is correct |
18 |
Correct |
8 ms |
7244 KB |
Output is correct |
19 |
Correct |
10 ms |
7112 KB |
Output is correct |
20 |
Incorrect |
4 ms |
5004 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4940 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
21592 KB |
Output is correct |
2 |
Correct |
80 ms |
21468 KB |
Output is correct |
3 |
Correct |
49 ms |
15932 KB |
Output is correct |
4 |
Correct |
12 ms |
7372 KB |
Output is correct |
5 |
Correct |
11 ms |
6400 KB |
Output is correct |
6 |
Correct |
24 ms |
8652 KB |
Output is correct |
7 |
Incorrect |
4 ms |
5068 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |