이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;
ll n,m,ar[N],sum,t,s,q,e,tut,flag,mark[N],tutmac[N];
vector<pair<int,ii> > v[N];
void f(int ind,ll len)
{
if(mark[ind])
return;
mark[ind]++;
if(ind==e)
{
flag=1;
return;
}
if(tutmac[ind])
sum=min(sum,len);
for(int i=0;i<v[ind].size();i++)
{
if(v[ind][i].se.se==tut)
continue;
int a=v[ind][i].fi;
ll b=v[ind][i].se.fi;
if(!mark[a])
f(a,len+b);
}
}
int main()
{
fast;
cin>>n>>s>>q>>e;
fo(i,1,n-1)
{
ll a,b,c;
cin>>a>>b>>c;
v[a].pb({b,{c,i}});
v[b].pb({a,{c,i}});
}
fo(i,1,s)
{
int a;
cin>>a;
tutmac[a]=1;
}
// cout<<endl;
fo(i,1,q)
{
int a,b;
sum=1e15;
flag=0;
cin>>b>>a;
fo(i,1,n)
mark[i]=0;
tut=b;
f(a,0ll);
if(flag)
{
cout<<"escaped"<<endl;
continue;
}
if(sum==1e15)
{
cout<<"oo"<<endl;
continue;
}
cout<<sum<<endl;
}
}
/* cd onedrive\desktop\kod
cls
Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/
컴파일 시 표준 에러 (stderr) 메시지
valley.cpp: In function 'void f(int, long long int)':
valley.cpp:38:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[ind].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... |