답안 #658901

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
658901 2022-11-15T11:51:51 Z JooDdae 산만한 고양이 (KOI17_cat) C++17
100 / 100
500 ms 85960 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n, m;

int in[300200], low[300200], cnt;
vector<int> v[300200];
stack<pair<int, int>> st;
vector<vector<pair<int, int>>> bcc;

int dfs(int u, int p){
    in[u] = low[u] = ++cnt;

    for(auto x : v[u]) if(x != p){
        if(in[u] > in[x]) st.push({u, x});

        if(in[x]) low[u] = min(low[u], in[x]);
        else{
            low[u] = min(low[u], dfs(x, u));
            if(low[x] >= in[u]){
                vector<pair<int, int>> b;
                while(st.top() != make_pair(u, x)) b.push_back(st.top()), st.pop();
                b.push_back(st.top()), st.pop();
                if(b.size() > 1) bcc.push_back(b);
            }
        }
    }

    return low[u];
}


int c[300300];

int main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    for(int i=1;i<=m;i++) {
        int a, b; cin >> a >> b;
        v[a].push_back(b), v[b].push_back(a);
    }

    dfs(1, 0);

    for(auto b : bcc) {
        map<int, int> mp;
        for(auto [x, y] : b) mp[x]++, mp[y]++;
        for(auto [x, y] : mp) if((int)b.size() - y <= (int)mp.size() - 2)
            // cout << x << " " << y << "\n";
            c[x]++;
    }

    ll ans = 0;
    for(int i=1;i<=n;i++) if(m-(int)v[i].size() <= n-2 && (bcc.empty() || c[i] == bcc.size())) ans += i;
    cout << ans;
}

Compilation message

cat.cpp: In function 'int main()':
cat.cpp:55:80: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i=1;i<=n;i++) if(m-(int)v[i].size() <= n-2 && (bcc.empty() || c[i] == bcc.size())) ans += i;
      |                                                                           ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 6 ms 8020 KB Output is correct
6 Correct 5 ms 7636 KB Output is correct
7 Correct 5 ms 8148 KB Output is correct
8 Correct 5 ms 7764 KB Output is correct
9 Correct 6 ms 8676 KB Output is correct
10 Correct 6 ms 8148 KB Output is correct
11 Correct 6 ms 8404 KB Output is correct
12 Correct 6 ms 8276 KB Output is correct
13 Correct 6 ms 7976 KB Output is correct
14 Correct 6 ms 7908 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7388 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 5 ms 7388 KB Output is correct
20 Correct 7 ms 8404 KB Output is correct
21 Correct 7 ms 8612 KB Output is correct
22 Correct 7 ms 8532 KB Output is correct
23 Correct 5 ms 7636 KB Output is correct
24 Correct 6 ms 7636 KB Output is correct
25 Correct 4 ms 7384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 19556 KB Output is correct
2 Correct 211 ms 19584 KB Output is correct
3 Correct 213 ms 19640 KB Output is correct
4 Correct 204 ms 19692 KB Output is correct
5 Correct 229 ms 19448 KB Output is correct
6 Correct 204 ms 20536 KB Output is correct
7 Correct 200 ms 20528 KB Output is correct
8 Correct 201 ms 20496 KB Output is correct
9 Correct 200 ms 20104 KB Output is correct
10 Correct 206 ms 20608 KB Output is correct
11 Correct 200 ms 21452 KB Output is correct
12 Correct 198 ms 21964 KB Output is correct
13 Correct 205 ms 21036 KB Output is correct
14 Correct 206 ms 21004 KB Output is correct
15 Correct 216 ms 22112 KB Output is correct
16 Correct 230 ms 33332 KB Output is correct
17 Correct 214 ms 35480 KB Output is correct
18 Correct 210 ms 29264 KB Output is correct
19 Correct 224 ms 35056 KB Output is correct
20 Correct 215 ms 31184 KB Output is correct
21 Correct 207 ms 26528 KB Output is correct
22 Correct 216 ms 46028 KB Output is correct
23 Correct 193 ms 51468 KB Output is correct
24 Correct 210 ms 27212 KB Output is correct
25 Correct 244 ms 51652 KB Output is correct
26 Correct 189 ms 85960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 84856 KB Output is correct
2 Correct 193 ms 84856 KB Output is correct
3 Correct 190 ms 84800 KB Output is correct
4 Correct 184 ms 84812 KB Output is correct
5 Correct 187 ms 84828 KB Output is correct
6 Correct 183 ms 84816 KB Output is correct
7 Correct 186 ms 84896 KB Output is correct
8 Correct 184 ms 84860 KB Output is correct
9 Correct 188 ms 84980 KB Output is correct
10 Correct 173 ms 72976 KB Output is correct
11 Correct 172 ms 72944 KB Output is correct
12 Correct 171 ms 72964 KB Output is correct
13 Correct 174 ms 72888 KB Output is correct
14 Correct 179 ms 72964 KB Output is correct
15 Correct 180 ms 61256 KB Output is correct
16 Correct 182 ms 61104 KB Output is correct
17 Correct 179 ms 61012 KB Output is correct
18 Correct 176 ms 61024 KB Output is correct
19 Correct 179 ms 60968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 6 ms 8020 KB Output is correct
6 Correct 5 ms 7636 KB Output is correct
7 Correct 5 ms 8148 KB Output is correct
8 Correct 5 ms 7764 KB Output is correct
9 Correct 6 ms 8676 KB Output is correct
10 Correct 6 ms 8148 KB Output is correct
11 Correct 6 ms 8404 KB Output is correct
12 Correct 6 ms 8276 KB Output is correct
13 Correct 6 ms 7976 KB Output is correct
14 Correct 6 ms 7908 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7388 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 5 ms 7388 KB Output is correct
20 Correct 7 ms 8404 KB Output is correct
21 Correct 7 ms 8612 KB Output is correct
22 Correct 7 ms 8532 KB Output is correct
23 Correct 5 ms 7636 KB Output is correct
24 Correct 6 ms 7636 KB Output is correct
25 Correct 4 ms 7384 KB Output is correct
26 Correct 197 ms 19556 KB Output is correct
27 Correct 211 ms 19584 KB Output is correct
28 Correct 213 ms 19640 KB Output is correct
29 Correct 204 ms 19692 KB Output is correct
30 Correct 229 ms 19448 KB Output is correct
31 Correct 204 ms 20536 KB Output is correct
32 Correct 200 ms 20528 KB Output is correct
33 Correct 201 ms 20496 KB Output is correct
34 Correct 200 ms 20104 KB Output is correct
35 Correct 206 ms 20608 KB Output is correct
36 Correct 200 ms 21452 KB Output is correct
37 Correct 198 ms 21964 KB Output is correct
38 Correct 205 ms 21036 KB Output is correct
39 Correct 206 ms 21004 KB Output is correct
40 Correct 216 ms 22112 KB Output is correct
41 Correct 230 ms 33332 KB Output is correct
42 Correct 214 ms 35480 KB Output is correct
43 Correct 210 ms 29264 KB Output is correct
44 Correct 224 ms 35056 KB Output is correct
45 Correct 215 ms 31184 KB Output is correct
46 Correct 207 ms 26528 KB Output is correct
47 Correct 216 ms 46028 KB Output is correct
48 Correct 193 ms 51468 KB Output is correct
49 Correct 210 ms 27212 KB Output is correct
50 Correct 244 ms 51652 KB Output is correct
51 Correct 189 ms 85960 KB Output is correct
52 Correct 191 ms 84856 KB Output is correct
53 Correct 193 ms 84856 KB Output is correct
54 Correct 190 ms 84800 KB Output is correct
55 Correct 184 ms 84812 KB Output is correct
56 Correct 187 ms 84828 KB Output is correct
57 Correct 183 ms 84816 KB Output is correct
58 Correct 186 ms 84896 KB Output is correct
59 Correct 184 ms 84860 KB Output is correct
60 Correct 188 ms 84980 KB Output is correct
61 Correct 173 ms 72976 KB Output is correct
62 Correct 172 ms 72944 KB Output is correct
63 Correct 171 ms 72964 KB Output is correct
64 Correct 174 ms 72888 KB Output is correct
65 Correct 179 ms 72964 KB Output is correct
66 Correct 180 ms 61256 KB Output is correct
67 Correct 182 ms 61104 KB Output is correct
68 Correct 179 ms 61012 KB Output is correct
69 Correct 176 ms 61024 KB Output is correct
70 Correct 179 ms 60968 KB Output is correct
71 Correct 485 ms 85488 KB Output is correct
72 Correct 472 ms 81916 KB Output is correct
73 Correct 480 ms 80412 KB Output is correct
74 Correct 460 ms 84212 KB Output is correct
75 Correct 344 ms 69536 KB Output is correct
76 Correct 388 ms 72844 KB Output is correct
77 Correct 372 ms 59896 KB Output is correct
78 Correct 378 ms 60368 KB Output is correct
79 Correct 461 ms 85228 KB Output is correct
80 Correct 500 ms 76772 KB Output is correct
81 Correct 284 ms 57964 KB Output is correct
82 Correct 309 ms 75512 KB Output is correct
83 Correct 339 ms 76760 KB Output is correct
84 Correct 378 ms 76112 KB Output is correct
85 Correct 462 ms 83824 KB Output is correct
86 Correct 315 ms 66960 KB Output is correct
87 Correct 315 ms 65660 KB Output is correct
88 Correct 130 ms 24016 KB Output is correct
89 Correct 128 ms 24212 KB Output is correct
90 Correct 123 ms 24204 KB Output is correct