이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define p(x,y) pair<ll,ll>(x,y)
#define BIT(i,x) ((x>>i)&1)
#define MASK(x) (1<<x)
#define ld long double
#define __builtin_popcount __builtin_popcountll
#define pll pair<ll,ll>
template<class T1,class T2>
bool maximize(T1 &x,T2 y)
{
if(x<y)
{
x=y;
return 1;
}
return 0;
}
template<class T1,class T2>
bool minimize(T1 &x,T2 y)
{
if(y<x)
{
x=y;
return 1;
}
return 0;
}
const ll M=1e9+7;
template <class T1,class T2>
void add(T1 &x,T2 y)
{
x+=y;
if(x>=M) x-=M;
}
template <class T1,class T2>
void sub(T1 &x, T2 y)
{
x-=y;
if(x<0) x+=M;
}
void online()
{
std::ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef thuc
freopen("input.inp","r",stdin);
freopen("output.out","w",stdout);
#else
#endif // thuc
}
const ll N=2e5+10;
ll vs[N],f[N],ban[N],n,m,q,src;
vector<ll> gr[N],rgr[N];
ll solve1(ll u)
{
if(vs[u]) return f[u];
vs[u]=1;
f[u]=-1e9;
if(u==src) return f[u]=0;
for(auto v:gr[u])
{
maximize(f[u],solve1(v)+1);
maximize(f[u],solve1(v)+1);
}
return f[u];
}
ll tr(ll u,ll y)
{
src=u;
for(int i=1;i<=n;i++)
{
ban[i]=0;
vs[i]=0;
}
for(int i=1;i<=y;i++)
{
ll x;
cin>>x;
ban[x]=1;
}
ll ans=-1;
for(int i=1;i<=n;i++)
{
if(!ban[i])maximize(ans,solve1(i));
}
return ans;
}
bool sub2()
{
for(int i=1;i<=m;i++)
{
ll u,v;
cin>>u>>v;
if(u>v) swap(u,v);
gr[u].push_back(v);
}
ll t,y;
cin>>t>>y;
cout<<tr(t,y);
return 0;
}
int main()
{
online();
cin>>n>>m>>q;
if(q==1) return sub2();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |