結果

問題 No.1436 Rgaph
ユーザー tarattata1tarattata1
提出日時 2021-03-19 23:48:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,559 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 101,712 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-12 05:15:26
合計ジャッジ時間 7,785 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <ctime>
#pragma warning(disable:4996) 

//#define ATCODER
#ifdef ATCODER
#include <atcoder/all>
#endif

typedef long long ll;
typedef unsigned long long ull;
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;
#ifdef ATCODER
using namespace atcoder;
#endif


void solve()
{
    int n, m;
    scanf("%d%d", &n, &m);
    vector<vector<pair<int,int>>> g(n);   // to,edge
    vector<int> a(m), b(m);
    int i;
    for (i = 0; i < m; i++) {
        scanf("%d%d", &a[i], &b[i]); a[i]--; b[i]--;
        g[a[i]].push_back(make_pair(b[i],i));
    }
    for (i = 0; i < m; i++) {
        int ans0 = 0;
        vector<int> pr(n);
        vector<int> dist(n, INF);
        queue<int> que;
        que.push(b[i]); dist[b[i]] = 0;
        while (!que.empty()) {
            int tmp = que.front(); que.pop();
            int k;
            for (k = 0; k < (int)g[tmp].size(); k++) {
                int ne = g[tmp][k].first;
                if (dist[ne] == INF) {
                    dist[ne] = dist[tmp] + 1;
                    pr[ne] = g[tmp][k].second;
                    if (ne == a[i]) {
                        ans0 = dist[ne];
                        break;
                    }
                    que.push(ne);
                }
            }
            if (ans0 > 0) {
                break;
            }
        }
        assert(ans0 > 0);
        if (ans0 % 2 == 0) {
            vector<int> ans(m);
            int curr = a[i];
            int cnt = 0;
            while (1) {
                int edge = pr[curr];
                ans[edge] = 1 - cnt; cnt = 1 - cnt;
                curr = a[edge];
                if (curr == a[i]) break;
            }
            int k;
            for (k = 0; k < m; k++) {
                if (ans[k]) printf("R");
                else printf("G");
            }
            printf("\n");
            return;
        }
    }
    printf("-1\n");
    return;
}


int main()
{
#if 1
    solve();
#else    
    int T, t;
    scanf("%d", &T);
    for (t = 0; t < T; t++) {
        //cout << "Case #" << t + 1 << ": ";
        solve();
    }
#endif
    return 0;
}
0