結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,384 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 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,376 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,380 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 3 ms
4,380 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 2 ms
4,380 KB
testcase_60 AC 1 ms
4,384 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 WA -
testcase_63 AC 9 ms
4,528 KB
testcase_64 WA -
testcase_65 AC 6 ms
4,380 KB
testcase_66 AC 5 ms
4,380 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 6 ms
4,380 KB
testcase_69 AC 7 ms
4,376 KB
testcase_70 AC 4 ms
4,380 KB
testcase_71 AC 3 ms
4,376 KB
testcase_72 AC 7 ms
4,376 KB
testcase_73 WA -
testcase_74 AC 6 ms
4,376 KB
testcase_75 WA -
testcase_76 AC 3 ms
4,376 KB
testcase_77 AC 5 ms
4,376 KB
testcase_78 WA -
testcase_79 AC 9 ms
4,380 KB
testcase_80 AC 7 ms
4,384 KB
testcase_81 AC 8 ms
4,636 KB
testcase_82 WA -
testcase_83 AC 99 ms
15,552 KB
testcase_84 WA -
testcase_85 AC 56 ms
10,536 KB
testcase_86 WA -
testcase_87 AC 103 ms
14,440 KB
testcase_88 AC 13 ms
5,008 KB
testcase_89 WA -
testcase_90 WA -
testcase_91 AC 44 ms
9,304 KB
testcase_92 AC 22 ms
6,568 KB
testcase_93 WA -
testcase_94 AC 72 ms
11,964 KB
testcase_95 AC 70 ms
12,000 KB
testcase_96 AC 93 ms
14,676 KB
testcase_97 AC 38 ms
8,400 KB
testcase_98 WA -
testcase_99 WA -
testcase_100 WA -
testcase_101 AC 20 ms
6,028 KB
testcase_102 AC 11 ms
4,680 KB
testcase_103 WA -
testcase_104 AC 34 ms
7,588 KB
testcase_105 WA -
testcase_106 AC 49 ms
8,804 KB
testcase_107 AC 117 ms
15,252 KB
testcase_108 WA -
testcase_109 AC 79 ms
12,756 KB
testcase_110 WA -
testcase_111 AC 71 ms
12,616 KB
testcase_112 AC 30 ms
7,488 KB
testcase_113 WA -
testcase_114 AC 40 ms
8,936 KB
testcase_115 AC 14 ms
5,252 KB
testcase_116 AC 49 ms
9,604 KB
testcase_117 AC 30 ms
7,296 KB
testcase_118 AC 94 ms
14,648 KB
testcase_119 WA -
testcase_120 AC 90 ms
14,216 KB
testcase_121 AC 25 ms
6,676 KB
testcase_122 WA -
testcase_123 AC 1 ms
4,376 KB
testcase_124 AC 168 ms
24,180 KB
testcase_125 AC 170 ms
24,100 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;
    }

    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);
        ans.emplace_back(mp[{u, v}]);
    }

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