結果

問題 No.1605 Matrix Shape
ユーザー nawawannawawan
提出日時 2021-07-16 21:58:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,213 bytes
コンパイル時間 2,412 ms
コンパイル使用メモリ 174,604 KB
実行使用メモリ 36,712 KB
最終ジャッジ日時 2023-09-20 13:50:51
合計ジャッジ時間 8,206 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
9,244 KB
testcase_01 AC 7 ms
9,236 KB
testcase_02 AC 6 ms
9,364 KB
testcase_03 AC 6 ms
9,356 KB
testcase_04 AC 7 ms
9,272 KB
testcase_05 AC 7 ms
9,264 KB
testcase_06 AC 6 ms
9,192 KB
testcase_07 AC 7 ms
9,116 KB
testcase_08 AC 7 ms
9,264 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
9,328 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 7 ms
9,228 KB
testcase_18 AC 7 ms
9,264 KB
testcase_19 AC 446 ms
35,984 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 452 ms
34,252 KB
testcase_23 AC 454 ms
36,712 KB
testcase_24 WA -
testcase_25 AC 106 ms
11,872 KB
testcase_26 AC 107 ms
11,872 KB
testcase_27 WA -
testcase_28 AC 106 ms
11,916 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 226 ms
17,684 KB
testcase_34 AC 110 ms
11,500 KB
testcase_35 AC 303 ms
26,268 KB
testcase_36 AC 171 ms
25,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int dfs(int now, int par, vector<vector<int>>&G, vector<int>&d){
    if(d[now] != -1) return d[now];
    d[now] = 0;
    for(int t: G[now]){
        if(t == now) continue;
        if(t == par) continue;
        d[now] = max(d[now], dfs(t, now, G, d));
    }
    d[now] += 1;
    return d[now];
}
int main(){
    int N;
    cin >> N;
    vector<int> H(N), W(N);
    vector<vector<int>>  G(200010);
    set<int> s;
    vector<int> cnt(200010, -1);
    for(int i = 0; i < N; i++){
        cin >> H[i] >> W[i];
        H[i]--;
        W[i]--;
        s.insert(H[i]);
        s.insert(W[i]);
        G[H[i]].push_back(W[i]);
        if(cnt[W[i]] == -1) cnt[W[i]] = 0;
        if(cnt[H[i]] == -1) cnt[H[i]] = 0;
        cnt[W[i]]++;
    }
    bool f = true;
    for(int i = 0; i < 200010; i++){
        if(cnt[i] == 0) f = false;
    }
    vector<int> d(200010, -1);
    if(f){
        d[W[0]] = 1;
    }
    for(int i = 0; i < 200010; i++){
        dfs(i, -1, G, d);
    }
    int temp = *max_element(d.begin(), d.end());
    if(f && temp == (int)s.size()) cout << s.size() << endl;
    else if(!f && temp == (int)s.size()) cout << 1 << endl;
    else cout << 0 << endl;
}
0