提交时间:2024-01-02 13:42:25

运行 ID: 24533

#include<iostream> #include<ctime> #include<random> #define timeMS (clock()*1000/CLOCKS_PER_SEC) using namespace std; mt19937_64 rng(time(0)); const int N=10010,M=1000010; int n,m,head[N],to[M<<1],nex[M<<1]; long long wei[M<<1]; void init(){ cin>>n>>m; for(int i=1;i<=m;i++){ int u,v;cin>>u>>v; to[i<<1]=v; nex[i<<1]=head[u]; head[u]=i<<1; to[i<<1|1]=u; nex[i<<1|1]=head[v]; head[v]=i<<1|1; wei[i<<1|1]=wei[i<<1]=rng()&(0x7fffffffffffffff); } } bool vis[N],tag[M]; long long hss[M]; int dis[N]; long long R[N]; int clk; void dfs(int nd,int fa){ clk++; if(clk>400000000){cout<<"No";exit(0);} vis[nd]=true; for(int i=head[nd];i;i=nex[i])if(to[i]!=fa){ if(vis[to[i]]){ int h=R[nd]^R[to[i]]^wei[i]; if(tag[dis[nd]-dis[to[i]]]&&h!=hss[dis[nd]-dis[to[i]]]){cout<<"Yes";exit(0);} tag[dis[nd]-dis[to[i]]]=true; hss[dis[nd]-dis[to[i]]]=h; } else dis[to[i]]=dis[nd]+1,R[to[i]]=R[nd]^wei[i],dfs(to[i],nd); } vis[nd]=false; } int main(){ // freopen("c.in","r",stdin); // freopen("c.out","w",stdout); init(); int s=rng()%1 +1; R[s]=0; dfs(s,0); cout<<"No"; return 0; }