提出 #41555339


ソースコード 拡げる

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}

void solve(){
    int n, q;
    cin >> n >> q;
    vector<set<int>> c(n);
    int ans = n;
    for (int _ = 0; _ < q; _++)
    {
        int t;
        cin >> t;
        if(t == 1)
        {
            int u, v;
            cin >> u >> v;
            --u, --v;
            if(c[u].empty())
            {
                --ans;
            }
            c[u].insert(v);
            if(c[v].empty())
            {
                --ans;
            }
            c[v].insert(u);
        }
        else
        {
            int v;
            cin >> v;
            --v;
            if(not c[v].empty())
            {
                ++ans;
                for(auto e : c[v])
                {
                    c[e].erase(v);
                    if(c[e].empty()) ++ans;
                }
                c[v].clear();
            }
        }
        cout << ans << '\n';
    }
    
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
}

提出情報

提出日時
問題 E - Isolation
ユーザ Motsu_xe
言語 C++ (GCC 9.2.1)
得点 425
コード長 1324 Byte
結果 AC
実行時間 362 ms
メモリ 45524 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 2
AC × 35
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 15 ms 3532 KiB
example_01.txt AC 2 ms 3488 KiB
hand_00.txt AC 345 ms 45524 KiB
hand_01.txt AC 230 ms 31460 KiB
hand_02.txt AC 226 ms 31468 KiB
hand_03.txt AC 129 ms 17140 KiB
hand_04.txt AC 67 ms 17156 KiB
hand_05.txt AC 131 ms 31468 KiB
hand_06.txt AC 246 ms 31520 KiB
hand_07.txt AC 255 ms 31432 KiB
random_00.txt AC 92 ms 17532 KiB
random_01.txt AC 131 ms 17484 KiB
random_02.txt AC 53 ms 17480 KiB
random_03.txt AC 138 ms 19652 KiB
random_04.txt AC 154 ms 17336 KiB
random_05.txt AC 232 ms 35872 KiB
random_06.txt AC 229 ms 29008 KiB
random_07.txt AC 165 ms 17664 KiB
random_08.txt AC 339 ms 44140 KiB
random_09.txt AC 362 ms 42760 KiB
random_10.txt AC 47 ms 17540 KiB
random_11.txt AC 92 ms 22020 KiB
random_12.txt AC 67 ms 17532 KiB
random_13.txt AC 96 ms 19580 KiB
random_14.txt AC 248 ms 29056 KiB
random_15.txt AC 52 ms 18272 KiB
random_16.txt AC 116 ms 23940 KiB
random_17.txt AC 230 ms 29808 KiB
random_18.txt AC 103 ms 20560 KiB
random_19.txt AC 240 ms 32116 KiB
random_20.txt AC 190 ms 30680 KiB
random_21.txt AC 96 ms 21892 KiB
random_22.txt AC 222 ms 30732 KiB
random_23.txt AC 284 ms 43472 KiB
random_24.txt AC 208 ms 36880 KiB