이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> >X[1<<18]; vector<int> J[1<<18], G;
int N, M, L, col[1<<18], cnts, dist[1<<18];
void dfs(int pos){
if(col[pos]>=1) return;
col[pos]=cnts; J[cnts].push_back(pos);
for(int i=0;i<X[pos].size();i++) dfs(X[pos][i].first);
}
void getdist(int pos){
for(int i:J[col[pos]]) dist[i]=(1<<30);
queue<int>que; que.push(pos); dist[pos]=0;
while(!que.empty()){
int p = que.front(); que.pop();
for(int i=0;i<(int)X[p].size();i++) {
int to = X[p][i].first;
if(dist[to]>dist[p]+X[p][i].second){
dist[to]=dist[p]+X[p][i].second;
que.push(to);
}
}
}
}
pair<int, int> radius(int pos){
getdist(J[pos][0]);
int EA=0,ret1=-1; for(int i:J[pos]) {if(ret1<dist[i]){ret1=dist[i];EA=i;}}
getdist(EA); vector<int> A1;
int EB=0,ret2=-1; for(int i:J[pos]) {if(ret2<dist[i]){ret2=dist[i];EB=i;A1.push_back(dist[i]);}}
getdist(EB); vector<int> A2;
for(int i:J[pos]) A2.push_back(dist[i]);
int ret=dist[EA];
for(int i=0;i<A1.size();i++){if(dist[EA]==A1[i]+A2[i]) ret=min(ret,max(A1[i],A2[i]));}
return make_pair(dist[EA], ret);
}
int travelTime(int NN, int MM, int LL, int A[], int B[], int T[]) {
N = NN; M = MM; L = LL;
for(int i=0;i<M;i++){
X[A[i]].push_back(make_pair(B[i], T[i]));
X[B[i]].push_back(make_pair(A[i], T[i]));
}
for(int i=0;i<N;i++){
if(col[i]>=1) continue;
cnts++;dfs(i);
}
int maxn=0;
for(int i=1;i<=cnts;i++){
pair<int, int>I1 = radius(i); maxn = max(maxn, I1.first);
//cout<<i<<":"<<I1.first<<" "<<I1.second<<endl;
G.push_back(I1.second);
}
sort(G.begin(), G.end());
reverse(G.begin(), G.end());
if(G.size()==1) return maxn;
int rem=(1<<30);
for(int i=0;i<(int)G.size();i++){
int v1 = G[i]; vector<int>v2;
for(int j=0;j<(int)G.size();j++){
if(j != i) v2.push_back(G[j]);
if(v2.size()==2) break;
}
int s1 = v1 + v2[0] + L;
int s2 = 0; if(v2.size()==2) s2 = v2[0] + v2[1] + L * 2;
rem = min(rem, max(s1, s2));
}
return max(maxn, rem);
}
컴파일 시 표준 에러 (stderr) 메시지
dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:11:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<X[pos].size();i++) dfs(X[pos][i].first);
~^~~~~~~~~~~~~~
dreaming.cpp: In function 'std::pair<int, int> radius(int)':
dreaming.cpp:39:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<A1.size();i++){if(dist[EA]==A1[i]+A2[i]) ret=min(ret,max(A1[i],A2[i]));}
~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |