# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
838607 |
2023-08-27T12:55:38 Z |
nnin |
Dreaming (IOI13_dreaming) |
C++14 |
|
36 ms |
14412 KB |
#include "dreaming.h"
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
vector<pair<int, int>> adj[100005];
vector<int> group[100005];
int maxdis[100005];
bool vis[100005];
int dsu[100005];
int par(int x) {
if(dsu[x]==x) return x;
return dsu[x] = par(dsu[x]);
}
void dfs(int cur, int prev, int dis) {
maxdis[cur] = max(maxdis[cur], dis);
for(auto next:adj[cur]) {
if(prev==next.f) continue;
dfs(next.f, cur, dis+next.s);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i=0;i<N;i++) dsu[i] = i;
for(int i=0;i<M;i++) {
adj[A[i]].push_back({B[i], T[i]});
adj[B[i]].push_back({A[i], T[i]});
dsu[par(A[i])] = par(B[i]);
}
for(int i=0;i<N;i++) group[par(i)].push_back(i);
int mx = INT_MIN, mx2 = INT_MIN;
for(int i=0;i<N;i++) {
if(group[i].empty()) continue;
dfs(group[i][0], -1, 0);
vis[group[i][0]] = 1;
int last = group[i][0];
for(int j=1;j<group[i].size();j++) {
int st = group[i][0];
for(int k=1;k<group[i].size();k++) {
if(!vis[group[i][k]] && maxdis[group[i][k]]>=maxdis[st] && maxdis[group[i][k]]>=maxdis[last]) {
st = group[i][k];
}
}
if(st==group[i][0]) break;
dfs(st, -1, 0);
vis[st] = 1;
last = st;
}
int mngroup = INT_MAX;
for(int j=0;j<group[i].size();j++) {
mngroup = min(mngroup, maxdis[group[i][j]]);
}
if(mngroup>=mx) {
mx2 = mx;
mx = mngroup;
} else if(mngroup>mx2) {
mx2 = mngroup;
}
}
if(mx2==INT_MIN) return mx;
return mx+mx2+L;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int j=1;j<group[i].size();j++) {
| ~^~~~~~~~~~~~~~~~
dreaming.cpp:44:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int k=1;k<group[i].size();k++) {
| ~^~~~~~~~~~~~~~~~
dreaming.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int j=0;j<group[i].size();j++) {
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
14412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
14412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
10128 KB |
Output is correct |
2 |
Incorrect |
25 ms |
10100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
14412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |