結果
問題 |
No.408 五輪ピック
|
ユーザー |
![]() |
提出日時 | 2025-04-19 14:00:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 5,000 ms |
コード長 | 1,797 bytes |
コンパイル時間 | 2,075 ms |
コンパイル使用メモリ | 197,760 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-04-19 14:00:55 |
合計ジャッジ時間 | 2,999 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:83:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 83 | scanf("%d%d",&n,&m); | ~~~~~^~~~~~~~~~~~~~ main.cpp:85:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 85 | scanf("%d%d",&x,&y); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; const int N=2e4+5,M=5e4+5; int n,m,k,cnt,dis[N],c[N],d[N],d1[N],head[N]; bool vis[N]; struct edge{ int to,nxt; }e[M<<1]; void add(int u,int v){ e[++cnt]=(edge){v,head[u]}; head[u]=cnt; } void bfs(){ queue<int> q; for(int i=head[1];i;i=e[i].nxt){ int v=e[i].to; q.push(v); } while(!q.empty()){ int p=q.front();q.pop(); for(int i=head[p];i;i=e[i].nxt){ int v=e[i].to; vis[v]=true; c[v]++; d1[v]=d[v],d[v]=p; } } } bool check(int x,int y){ if(c[x]==1){ if(c[y]==1){ if(d[y]!=x&&d[y]!=d[x]&&d[x]!=y) return true; return false; } else if(c[y]==2){ if(d[y]!=x&&d[y]!=d[x]&&d[x]!=y) return true; if(d1[y]!=x&&d1[y]!=d[x]&&d[x]!=y) return true; return false; } else{ if(d[x]!=y) return true; return false; } } else if(c[x]==2){ if(c[y]==1){ if(d[y]!=x&&d[y]!=d[x]&&d[x]!=y) return true; if(d[y]!=x&&d[y]!=d1[x]&&d1[x]!=y) return true; return false; } else if(c[y]==2){ if(d[y]!=x&&d[y]!=d[x]&&d[x]!=y) return true; if(d1[y]!=x&&d1[y]!=d[x]&&d[x]!=y) return true; if(d[y]!=x&&d[y]!=d1[x]&&d1[x]!=y) return true; if(d1[y]!=x&&d1[y]!=d1[x]&&d1[x]!=y) return true; return true; } else{ return true; } } else{ if(c[y]==1){ if(d[y]!=x) return true; return false; } else if(c[y]==2){ return true; } else return true; } } int main(){ // freopen("circle.in","r",stdin); // freopen("circle.out","w",stdout); scanf("%d%d",&n,&m); for(int i=1,x,y;i<=m;i++){ scanf("%d%d",&x,&y); add(x,y),add(y,x); } bfs(); for(int i=2;i<=n;i++){ if(!vis[i]) continue; for(int j=head[i];j;j=e[j].nxt){ int v=e[j].to; if(!vis[v]||v==1) continue; if(check(i,v)){ printf("YES"); return 0; } } } printf("NO"); return 0; }