QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#500691 | #6536. Lawyers | cocoa_chan# | ML | 7ms | 34544kb | C++17 | 1.0kb | 2024-08-01 18:09:09 | 2024-08-01 18:09:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,m,i,j,k,l,r,x,y,z,w,s,t,a[1100000],b[1100000],ok[1100000],chk[1100000];
vector<ll> v[1100000];
pair<ll,ll> p[1100000];
map<pair<ll,ll>,ll> mp;
ll f(ll x,ll y)
{
chk[x]=1;
ll i,s=ok[x];
for(i=0;i<v[x].size();i++)
{
if(v[x][i]==y)
continue;
s|=f(v[x][i],x);
}
return s;
}
int main()
{
scanf("%lld %lld",&n,&m);
for(i=1;i<=m;i++)
{
scanf("%lld %lld",&x,&y);
p[i]={x,y};
mp[p[i]]=1;
}
for(i=1;i<=m;i++)
{
if(mp[{p[i].second,p[i].first}]==0)
{
ok[p[i].second]=1;
}
else
{
v[p[i].first].push_back(p[i].second);
}
}
for(i=1;i<=n;i++)
{
if(chk[i]==0)
{
if(!f(i,0))
{
printf("NO");
return 0;
}
}
}
printf("YES");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 34476kb
input:
3 3 1 2 2 3 3 1
output:
YES
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 32484kb
input:
4 6 1 2 1 3 1 4 2 3 2 4 3 4
output:
NO
result:
ok answer is NO
Test #3:
score: 0
Accepted
time: 0ms
memory: 30440kb
input:
4 4 1 2 2 1 3 4 4 3
output:
NO
result:
ok answer is NO
Test #4:
score: 0
Accepted
time: 7ms
memory: 30380kb
input:
4 6 1 2 2 1 1 3 3 1 1 4 4 1
output:
NO
result:
ok answer is NO
Test #5:
score: 0
Accepted
time: 0ms
memory: 34544kb
input:
4 7 1 2 2 1 1 3 3 1 1 4 4 1 2 4
output:
YES
result:
ok answer is YES
Test #6:
score: -100
Memory Limit Exceeded
input:
5 12 2 4 3 1 3 4 1 2 4 2 2 3 5 4 1 3 1 4 4 1 3 2 4 3