#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#include "dreaming.h"
typedef pair<int, int> ii;
typedef vector<ii> vii;
vector<vii> adj;
int longest[10000];
int ans=0;
int maxans=0;
vector<bool> vis;
set<int> tree;
bool dfs(int s, int pre=-1){
vis[s] = true;
tree.insert(s);
maxans = max(ans, maxans);
for(int i=0;i<adj[s].size();i++){
if(adj[s][i].F!=pre){
ans+=adj[s][i].S;
dfs(adj[s][i].F, s);
ans-=adj[s][i].S;
}
}
}
int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
adj.assign(n+1, vii());
vis.assign(n+1, false);
for(int i=0;i<m;i++){
adj[A[i]].push_back(ii(B[i], T[i]));
adj[B[i]].push_back(ii(A[i], T[i]));
}
for(int i=0;i<n;i++){
maxans = 0;
ans = 0;
dfs(i);
longest[i] = maxans;
//cout<<longest[i]<<" ";
}
vis.assign(n+1, false);
tree.clear();
ans = 0;
int minm = 100000;
//cout<<endl;
vector<int> treeans;
int max1=0, max2=0;
for(int i=0;i<n;i++){
if(!vis[i]){
dfs(i);
minm = 1000000;
for(set<int>::iterator it=tree.begin();it!=tree.end();it++){
minm = min(minm, longest[(*it)]);
}
//cout<<minm<<" ";
if(minm>max1) max2=max1, max1=minm;
else if(minm>max2) max2=minm;
treeans.push_back(minm);
tree.clear();
}
}
return max1+max2+L;
}
Compilation message
dreaming.cpp: In function 'bool dfs(int, int)':
dreaming.cpp:19:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<adj[s].size();i++){
~^~~~~~~~~~~~~~
dreaming.cpp:26:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
15992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
15992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
15992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
32 ms |
11580 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
15992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
15992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |