結果
問題 |
No.1436 Rgaph
|
ユーザー |
👑 ![]() |
提出日時 | 2021-03-19 22:10:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,437 bytes |
コンパイル時間 | 2,079 ms |
コンパイル使用メモリ | 207,316 KB |
最終ジャッジ日時 | 2025-01-19 18:36:15 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 1 |
other | AC * 15 WA * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:29:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | scanf("%d%d",&N,&M); | ~~~~~^~~~~~~~~~~~~~ main.cpp:34:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | int u,v; scanf("%d%d",&u,&v); u--; v--; | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) struct Edge{ int to,i; }; struct Edge2{ int u,v; }; int N,M; vector<vector<Edge>> E,rE; vector<Edge2> J; vector<int> D; vector<int> B; void bfs(int s){ D.assign(N,-1); queue<int> Q; D[s]=0; Q.push(s); while(Q.size()){ int p=Q.front(); Q.pop(); for(auto e:E[p]) if(D[e.to]==-1){ D[e.to]=D[p]+B[e.i]; Q.push(e.to); } } } int main(){ scanf("%d%d",&N,&M); E.resize(N); rE.resize(N); J.resize(M); rep(i,M){ int u,v; scanf("%d%d",&u,&v); u--; v--; E[u].push_back({v,i}); rE[v].push_back({u,i}); J.push_back({u,v}); } int cyd=1000000, cys=-1, cyt=-1, cye=-1; B.assign(M,1); rep(s,N){ bfs(s); for(auto e:rE[s]){ if(D[e.to]%2==0) if(D[e.to]+1<cyd){ cyd=D[e.to]+1; cys=s; cyt=e.to; cye=e.i; } } rep(i,N) if(D[i]==-1){ printf("-1\n"); return 0; } } if(cys==-1){ printf("-1\n"); return 0; } vector<int> Cy, Cye; Cy.push_back(cys); Cye.push_back(cye); bfs(cys); while(cyt!=cys){ Cy.push_back(cyt); for(auto e:rE[cyt]) if(D[e.to]<D[cyt]){ cyt=e.to; break; } } rep(i,Cy.size()) B[Cy[i]]=i%2*2-1; bool ok=false; rep(s,N){ bfs(s); rep(i,N) if(D[i]>0) ok=true; } if(!ok){ printf("-1\n"); return 0; } rep(i,M) printf((B[i]==1)?"R":"G"); printf("\n"); return 0; }