이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const long long mod=1e9+7;
long long n,m,l,st1,st2,vis[100005],mn=1e10,dis[100005],mx;
vector<pair<int,int> >gr[100005];
void dfs(int x)
{
vis[x]=1;
for(int i=0;i<gr[x].size();i++)
{
int u=gr[x][i].first;
if(vis[u])continue;
dfs(u);
}
}
void cal(int x)
{
vis[x]=1;
for(int i=0;i<gr[x].size();i++)
{
int u=gr[x][i].first,w=gr[x][i].second;
if(vis[u])continue;
cal(u);
dis[x]=max(dis[x],dis[u]+w);
}
}
void root(int x)
{
vis[x]=1;
mn=min(mn,dis[x]);
mx=max(mx,dis[x]);
multiset<int>ms;
ms.insert(0);
for(int i=0;i<gr[x].size();i++)
{
int u=gr[x][i].first,w=gr[x][i].second;
ms.insert(dis[u]+w);
}
for(int i=0;i<gr[x].size();i++)
{
int u=gr[x][i].first,w=gr[x][i].second;
if(vis[u])continue;
ms.erase(ms.lower_bound(dis[u]+w));
long long oldx=dis[x],oldu=dis[u];
dis[x]=*--ms.end();
dis[u]=max(dis[u],dis[x]+w);
root(u);
dis[x]=oldx;
dis[u]=oldu;
ms.insert(dis[u]+w);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
n=N,m=M,l=L;
for(int i=0;i<m;i++)
{
gr[A[i]+1].push_back({B[i]+1,T[i]});
gr[B[i]+1].push_back({A[i]+1,T[i]});
}
for(int i=1;i<=n;i++)
{
if(vis[i]==0&&st1==0)
{
dfs(i);
st1=i;
}
if(vis[i]==0&&st1)
{
dfs(i);
st2=i;
}
}
memset(vis,0,sizeof vis);
cal(st1);
memset(vis,0,sizeof vis);
root(st1);
long long ans=mn;
mn=1e10;
memset(vis,0,sizeof vis);
cal(st2);
memset(vis,0,sizeof vis);
root(st2);
return max(mx,ans+mn+l);
}
컴파일 시 표준 에러 (stderr) 메시지
dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:12:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<gr[x].size();i++)
~^~~~~~~~~~~~~
dreaming.cpp: In function 'void cal(int)':
dreaming.cpp:22:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<gr[x].size();i++)
~^~~~~~~~~~~~~
dreaming.cpp: In function 'void root(int)':
dreaming.cpp:37:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<gr[x].size();i++)
~^~~~~~~~~~~~~
dreaming.cpp:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<gr[x].size();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... |