# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
210665 |
2020-03-18T01:25:01 Z |
peuch |
Dreaming (IOI13_dreaming) |
C++17 |
|
92 ms |
19320 KB |
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const int MAXN = 1e5 + 10;
int marc[MAXN], dist[MAXN], longDist[2][MAXN];
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]);
}
for(int i = 0; i < N; i++){
if(marc[i] == 3) continue;
dist[i] = 0;
int side1 = dfs1(i);
longDist[0][side1] = 0;
int side2 = dfs2(side1);
// printf("group: %d ends = %d and %d\n", group.size(), side1, side2);
longDist[1][side2] = 0;
group.push_back(dfs3(side2));
}
// printf("%d\n", group.size());
// for(int i = 0; i < group.size(); i++)
// printf("%d ", group[i]);
// printf("\n");
int ret = 0;
if(group.size() == 1){
for(int i = 0; i < N; i++)
ret = max(ret, longDist[0][i]);
return ret;
}
for(int i = 1; i < group.size(); i++){
ret = max(ret, group[i] + group[i - 1] + L);
group[i] = min(max(group[i], group[i - 1] + L), max(group[i - 1], group[i] + L));
}
return ret;
}
int dfs1(int cur){
marc[cur] = 1;
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));
}
return ret;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:44:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < group.size(); i++){
~~^~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs1(int)':
dreaming.cpp:55:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < ar[cur].size(); i++){
~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs2(int)':
dreaming.cpp:70:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < ar[cur].size(); i++){
~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs3(int)':
dreaming.cpp:84:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < ar[cur].size(); i++){
~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
19320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
19320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
19320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
11516 KB |
Output is correct |
2 |
Incorrect |
46 ms |
11516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
19320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
19320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |