結果

問題 No.1254 補強への架け橋
ユーザー first_vilfirst_vil
提出日時 2020-10-09 23:01:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 3,529 bytes
コンパイル時間 2,044 ms
コンパイル使用メモリ 207,460 KB
実行使用メモリ 13,808 KB
最終ジャッジ日時 2023-09-27 19:15:35
合計ジャッジ時間 11,053 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,384 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 1 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,376 KB
testcase_58 AC 1 ms
4,380 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 1 ms
4,376 KB
testcase_62 AC 2 ms
4,376 KB
testcase_63 AC 4 ms
4,376 KB
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 3 ms
4,380 KB
testcase_66 AC 3 ms
4,376 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 3 ms
4,376 KB
testcase_69 AC 4 ms
4,376 KB
testcase_70 AC 2 ms
4,376 KB
testcase_71 AC 2 ms
4,380 KB
testcase_72 AC 4 ms
4,376 KB
testcase_73 AC 3 ms
4,380 KB
testcase_74 AC 4 ms
4,376 KB
testcase_75 AC 3 ms
4,380 KB
testcase_76 AC 2 ms
4,380 KB
testcase_77 AC 2 ms
4,376 KB
testcase_78 AC 3 ms
4,376 KB
testcase_79 AC 4 ms
4,376 KB
testcase_80 AC 4 ms
4,376 KB
testcase_81 AC 4 ms
4,376 KB
testcase_82 AC 4 ms
4,376 KB
testcase_83 AC 34 ms
9,052 KB
testcase_84 AC 33 ms
8,776 KB
testcase_85 AC 20 ms
6,748 KB
testcase_86 AC 29 ms
8,132 KB
testcase_87 AC 30 ms
8,616 KB
testcase_88 AC 6 ms
4,376 KB
testcase_89 AC 34 ms
9,104 KB
testcase_90 AC 22 ms
6,940 KB
testcase_91 AC 18 ms
6,140 KB
testcase_92 AC 10 ms
4,696 KB
testcase_93 AC 27 ms
7,788 KB
testcase_94 AC 25 ms
7,552 KB
testcase_95 AC 24 ms
7,456 KB
testcase_96 AC 33 ms
8,916 KB
testcase_97 AC 14 ms
5,656 KB
testcase_98 AC 30 ms
8,788 KB
testcase_99 AC 19 ms
6,768 KB
testcase_100 AC 35 ms
9,108 KB
testcase_101 AC 11 ms
4,612 KB
testcase_102 AC 6 ms
4,376 KB
testcase_103 AC 10 ms
4,708 KB
testcase_104 AC 13 ms
5,408 KB
testcase_105 AC 26 ms
7,716 KB
testcase_106 AC 15 ms
5,948 KB
testcase_107 AC 35 ms
9,112 KB
testcase_108 AC 33 ms
9,056 KB
testcase_109 AC 29 ms
7,824 KB
testcase_110 AC 23 ms
7,260 KB
testcase_111 AC 27 ms
7,800 KB
testcase_112 AC 12 ms
5,092 KB
testcase_113 AC 23 ms
7,352 KB
testcase_114 AC 16 ms
5,872 KB
testcase_115 AC 6 ms
4,376 KB
testcase_116 AC 19 ms
6,496 KB
testcase_117 AC 14 ms
5,328 KB
testcase_118 AC 30 ms
8,780 KB
testcase_119 AC 21 ms
6,464 KB
testcase_120 AC 32 ms
8,512 KB
testcase_121 AC 11 ms
5,088 KB
testcase_122 AC 17 ms
6,136 KB
testcase_123 AC 2 ms
4,376 KB
testcase_124 AC 50 ms
13,768 KB
testcase_125 AC 53 ms
13,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n"
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; cin >> n;
    vector<vector<pair<int,int>>> g(n);
    FOR(i, 0, n) {
        int a, b; cin >> a >> b;
        --a, --b;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }

    VI q(n);
    VI p;
    auto dfs = [&](auto&& self, int cur, int par)->int {
        q[cur] = 1;
        for (auto [to,num] : g[cur]) {
            if (to == par)continue;
            if (q[to] == -1)break;
            if (q[to] == 1) {
                q[cur] = -1;
                p.push_back(num + 1);
                return to;
            }
            if (int res = self(self, to, cur); res == -2) {
                return -2;
            }
            else if(res != -1) {
                q[cur] = -1;
                p.push_back(num + 1);
                if (res == cur)return -2;
                return res;
            }
        }
        return -1;
    };
    dfs(dfs, 0, -1);
    print(p.size());
    print(p);

    return 0;
}
0