結果

問題 No.1254 補強への架け橋
ユーザー micheeeeell1001micheeeeell1001
提出日時 2020-10-09 22:45:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,153 bytes
コンパイル時間 2,870 ms
コンパイル使用メモリ 214,092 KB
実行使用メモリ 24,256 KB
最終ジャッジ日時 2023-09-27 18:42:15
合計ジャッジ時間 12,845 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 WA -
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 WA -
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 WA -
testcase_63 AC 9 ms
4,444 KB
testcase_64 WA -
testcase_65 AC 6 ms
4,376 KB
testcase_66 AC 5 ms
4,380 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 6 ms
4,380 KB
testcase_69 AC 7 ms
4,380 KB
testcase_70 AC 4 ms
4,376 KB
testcase_71 AC 3 ms
4,380 KB
testcase_72 AC 7 ms
4,472 KB
testcase_73 WA -
testcase_74 AC 7 ms
4,380 KB
testcase_75 WA -
testcase_76 AC 2 ms
4,376 KB
testcase_77 AC 5 ms
4,376 KB
testcase_78 WA -
testcase_79 AC 9 ms
4,416 KB
testcase_80 AC 8 ms
4,380 KB
testcase_81 AC 9 ms
4,384 KB
testcase_82 WA -
testcase_83 AC 106 ms
15,520 KB
testcase_84 WA -
testcase_85 AC 58 ms
10,464 KB
testcase_86 WA -
testcase_87 AC 99 ms
14,372 KB
testcase_88 AC 14 ms
4,980 KB
testcase_89 WA -
testcase_90 WA -
testcase_91 AC 43 ms
9,412 KB
testcase_92 AC 22 ms
6,516 KB
testcase_93 WA -
testcase_94 AC 73 ms
11,972 KB
testcase_95 AC 70 ms
12,156 KB
testcase_96 AC 106 ms
14,628 KB
testcase_97 AC 39 ms
8,328 KB
testcase_98 WA -
testcase_99 WA -
testcase_100 WA -
testcase_101 AC 20 ms
6,020 KB
testcase_102 AC 11 ms
4,712 KB
testcase_103 WA -
testcase_104 AC 32 ms
7,504 KB
testcase_105 WA -
testcase_106 AC 42 ms
8,780 KB
testcase_107 AC 105 ms
15,404 KB
testcase_108 WA -
testcase_109 AC 77 ms
12,776 KB
testcase_110 WA -
testcase_111 AC 77 ms
12,520 KB
testcase_112 AC 31 ms
7,236 KB
testcase_113 WA -
testcase_114 AC 42 ms
8,512 KB
testcase_115 AC 15 ms
5,068 KB
testcase_116 AC 57 ms
9,656 KB
testcase_117 AC 32 ms
7,480 KB
testcase_118 AC 101 ms
14,728 KB
testcase_119 WA -
testcase_120 AC 92 ms
14,084 KB
testcase_121 AC 25 ms
6,664 KB
testcase_122 WA -
testcase_123 AC 2 ms
4,376 KB
testcase_124 AC 194 ms
24,256 KB
testcase_125 AC 192 ms
24,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll
const long double pi = 3.14159265358979323846;

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;
}
vector<vector<ll>> graph;
vector<ll> used;
ll pre_dfs(ll now, ll pre = -1) {
    used[now] = 1;
    ll ret = -1;
    for (auto &to : graph[now]) {
        if (to == pre) continue;
        if (used[to]) return to;
        chmax(ret, pre_dfs(to, now));
    }

    return ret;
}

vector<ll> path;
bool dfs(ll s, ll now, ll pre = -1) {
    used[now] = 1;
    bool ret = false;
    for (auto &to : graph[now]) {
        if (to == pre) continue;
        if (to == s) {
            path.emplace_back(now);
            return true;
        }
        if (used[to]) continue;
        ret |= dfs(s, to, now);
        if (ret) break;
    }
    if (ret) path.emplace_back(now);
    return ret;
}

// グラフ中の閉路をpathに入れる
// 返り値は閉路があるかどうか
// 極小閉路ではないので注意
bool closed_path() {
    ll n = graph.size();
    used.assign(n, 0);
    ll s = -1;
    for (int i = 0; i < graph.size(); i++) {
        if (!used[i]) chmax(s, pre_dfs(i));
    }
    if (s == -1) return false;
    fill(all(used), 0);
    dfs(s, s);
    return true;
}

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    graph.resize(n);
    map<Pll, ll> mp;
    rep(i, 0, n) {
        ll u,v; cin >> u >> v;
        u--;
        v--;
        graph[u].emplace_back(v);
        graph[v].emplace_back(u);
        if (u > v) swap(u, v);
        if(mp.count({u, v})){
            cout << 2 << "\n";
            cout << mp[{u, v}] << " " << i + 1 << "\n";
            return 0;
        }
        mp[{u, v}] = i + 1;
    }

    assert(closed_path());
    debug(path);
    ll m = path.size();
    vector<ll> ans;
    rep(i, 0, m) {
        ll u = path[i], v = path[(i + 1) % m];
        if (u > v) swap(u, v);
        assert(mp[Pll(u, v)]);
        ans.emplace_back(mp[{u, v}]);
    }

    cout << ans.size() << "\n";
    print(ans);
}
0