이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dreaming.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define Pb push_back
using namespace std;
const int N=2e5+5;
long long res,X,n,m,l,ko,Y,Res,f[N];
vector < pair < long long , long long > > v[N];
vector < long long > V,G;
void Dfs(long long x,long long p,long long val,long long j) {
if (res<=val) { X=x; res=val; }
f[x]=j;
for (int i=0; i<v[x].size(); i++)
if (f[v[x][i].F]!=j && v[x][i].F!=p) Dfs(v[x][i].F,x,val+v[x][i].S,j);
}
void Df(long long x,long long p,long long val,long long j) {
if (ko) { V.push_back(val); return ; }
if (x==Y) { ko=1; return ; }
f[x]=j;
for (int i=0; i<v[x].size(); i++)
if (f[v[x][i].F]!=j && v[x][i].F!=p) {
Df(v[x][i].F,x,val+v[x][i].S,j);
if (ko) { V.push_back(val); return ; }
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
int n=N,m=M,l=L;
for (int i=0; i<m; i++) {
v[A[i]].Pb({B[i],T[i]});
v[B[i]].Pb({A[i],T[i]});
}
for (int i=0; i<n; i++)
if (!f[i]) {
V.clear();
res=0,X=0,Y=0,ko=0;
Dfs(i,i,0,1);
res=0,Y=X;
Dfs(X,X,0,2);
Res=max(Res,res);
Df(X,X,0,3);
long long Nq=1e13;
for (int j=0; j<V.size(); j++)
Nq=min(Nq,max(res-V[j],V[j]));
if (Nq==1e13) Nq=0;
G.push_back(Nq);
}
sort(G.begin(),G.end());
if (G.size()==1) { return Res; return 0; }
if (G.size()==2) { return max(Res,G[0]+G[1]+l); return 0; }
return max(Res,max(G[G.size()-1]+G[G.size()-2]+l,G[G.size()-3]+G[G.size()-2]+2*l));
}
컴파일 시 표준 에러 (stderr) 메시지
dreaming.cpp: In function 'void Dfs(long long int, long long int, long long int, long long int)':
dreaming.cpp:15:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<v[x].size(); i++)
~^~~~~~~~~~~~
dreaming.cpp: In function 'void Df(long long int, long long int, long long int, long long int)':
dreaming.cpp:23:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<v[x].size(); i++)
~^~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:48:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0; j<V.size(); j++)
~^~~~~~~~~
# | 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... |