結果

問題 No.1436 Rgaph
ユーザー 👑 NachiaNachia
提出日時 2021-03-19 22:09:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,500 bytes
コンパイル時間 2,613 ms
コンパイル使用メモリ 214,556 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 17:05:33
合計ジャッジ時間 5,989 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 13 ms
5,376 KB
testcase_12 AC 15 ms
5,376 KB
testcase_13 AC 13 ms
5,376 KB
testcase_14 AC 17 ms
5,376 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 14 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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"); printf("break 1\n"); return 0; }
  }

  if(cys==-1){ printf("-1\n"); printf("break 2\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"); printf("break 3\n"); return 0; }
  rep(i,M) printf((B[i]==1)?"R":"G"); printf("\n");

  return 0;
}
0