QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#304208 | #8011. Institute | MagicDark (Yi Yao, Haikun Zhao, Xingqian Wang)# | WA | 5ms | 24052kb | C++14 | 2.5kb | 2024-01-13 16:34:21 | 2024-01-13 16:34:21 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define mk make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
return x*f;
}
const int mod=998244353;
int ksm(int x,int y,int p=mod){
int ans=1;
for(int i=y;i;i>>=1,x=1ll*x*x%p)if(i&1)ans=1ll*ans*x%p;
return ans%p;
}
int inv(int x,int p=mod){return ksm(x,p-2,p)%p;}
mt19937 rnd(time(0));
int randint(int l,int r){return rnd()%(r-l+1)+l;}
void add(int &x,int v){x+=v;if(x>=mod)x-=mod;}
void Mod(int &x){if(x>=mod)x-=mod;}
int cmod(int x){if(x>=mod)x-=mod;return x;}
void cmax(int &x,int v){x=max(x,v);}
void cmin(int &x,int v){x=min(x,v);}
const int N=3e5+5;
vector<pair<int,int> >G[N];
int n,m,ban[10];
int low[N],dfn[N],dfc,stk[N],top,scc[N],sc,sz[N];
bool ins[N],can[N];
void dfs(int u){
// cout<<"dfs "<<u<<endl;
stk[++top]=u,dfn[u]=low[u]=++dfc,ins[u]=1;
for(auto [v,w]:G[u]){
if(ban[w])continue;
// cout<<" -> "<<v<<endl;
if(!dfn[v])dfs(v),cmin(low[u],low[v]);
else if(ins[v])cmin(low[u],dfn[v]);
}
// cout<<"u = "<<u<<" dfn = "<<dfn[u]<<" low = "<<low[u]<<endl;
if(dfn[u]!=low[u])return ;
scc[u]=++sc,ins[u]=0,sz[sc]=1;
while(stk[top]!=u)scc[stk[top]]=sc,ins[stk[top]]=0,top--,sz[sc]++;top--;
}
struct Edge{int u,v,t;Edge(int U=0,int V=0,int T=0):u(U),v(V),t(T){}};
vector<Edge>edges;
vector<int>G2[N];
void solve(){
n=read(),m=read(),ban[1]=1;
for(int i=1;i<=m;i++){
int u=read(),v=read(),t=read();
edges.emplace_back(Edge(u,v,t));
G[u].emplace_back(mk(v,t));
}
for(int i=1;i<=n;i++)if(!dfn[i])dfs(i);
for(int i=1;i<=n;i++)can[i]=(sz[scc[i]]<=1);
// cout<<"scc = ";for(int i=1;i<=n;i++)cout<<scc[i]<<" ";puts("");
// cout<<"can = ";for(int i=1;i<=n;i++)cout<<can[i]<<" ";puts("");
memset(dfn,0,sizeof(dfn)),memset(low,0,sizeof(low));
memset(stk,0,sizeof(stk)),memset(scc,0,sizeof(scc));
memset(ins,0,sizeof(ins)),dfc=top=sc=0;
ban[1]=0;vector<int>ind(n+1,0);
for(int i=1;i<=n;i++)if(!dfn[i])dfs(i);
for(auto [u,v,w]:edges){
u=scc[u],v=scc[v];
if(u==v)continue;
G2[v].emplace_back(u),ind[u]++;
}
queue<int>q;
for(int i=1;i<=sc;i++)if(ind[i]==0)q.push(i);
while(q.size()){
int x=q.front();q.pop();
for(int y:G2[x]){
can[y]|=can[x];
if(--ind[y]==0)q.push(y);
}
}
if(can[scc[1]])puts("Yes");
else puts("No");
}
signed main(void){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 23504kb
input:
3 4 1 2 1 2 3 2 3 2 1 3 1 2
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 24052kb
input:
6 8 1 2 1 2 3 2 3 2 2 3 4 1 4 1 2 1 5 2 5 4 2 6 1 2
output:
No
result:
ok answer is NO
Test #3:
score: 0
Accepted
time: 3ms
memory: 23816kb
input:
1000 1000 141 466 1 634 659 1 179 96 2 445 344 2 993 974 1 310 114 2 32 333 1 758 832 1 834 1 1 874 825 2 480 61 2 765 100 2 804 616 1 496 545 1 786 261 2 899 263 1 962 237 2 766 807 1 561 583 1 35 425 1 201 291 1 6 142 1 61 386 2 785 861 2 386 986 2 288 769 2 850 209 1 660 259 2 258 143 2 646 715 2...
output:
Yes
result:
ok answer is YES
Test #4:
score: -100
Wrong Answer
time: 5ms
memory: 23180kb
input:
1000 3000 719 279 2 857 23 1 984 625 2 904 509 2 892 456 2 589 195 2 718 932 2 608 363 1 474 672 1 217 993 2 165 895 2 727 329 2 932 404 2 952 146 2 201 272 2 412 895 2 228 267 2 396 365 2 813 794 2 259 250 1 968 764 2 100 76 2 924 665 2 981 931 2 292 975 2 903 649 2 793 101 2 54 703 1 853 58 2 356 ...
output:
No
result:
wrong answer expected YES, found NO