Submission #574328

# Submission time Handle Problem Language Result Execution time Memory
574328 2022-06-08T10:51:03 Z FatihSolak Parachute rings (IOI12_rings) C++17
100 / 100
2749 ms 161492 KB
#include <bits/stdc++.h>
using namespace std;
#define N 1000005
struct DSU{
    vector<int> ch;
    vector<int> cnt;
    vector<int> sz;
    vector<int> par;
    vector<int> cycles;
    int n; 
    int maxi;
    DSU(int size){
        n = size;
        maxi = 0;
        cnt.assign(n,0);
        sz.assign(n,1);
        ch.assign(n,0);
        par.assign(n,0);
        for(int i = 0;i<n;i++){
            par[i] = i;
        }
    }
    int find(int a){
        if(a == par[a])return a;
        return par[a] = find(par[a]);
    }
    void add(int a,int b){
        ch[a]++;
        ch[b]++;
        maxi = max(maxi,ch[a]);
        maxi = max(maxi,ch[b]);
        a = find(a);
        b = find(b);
        if(a == b){
            cnt[b]++;
            if(cnt[b] >= sz[b]){
                cycles.push_back(sz[b]);
            }
            return;
        }
        par[a] = b;
        sz[b] += sz[a];
        cnt[b] += cnt[a] + 1;
        cnt[a] = sz[a] = 0;
        if(cnt[b] >= sz[b]){
            cycles.push_back(sz[b]);
        }
    }

};
int n;
vector<int> nodes;
vector<DSU> graphs;
vector<int> adj[N];
void Init(int N_) {
    n = N_;
    nodes.push_back(-1);
    DSU tmp(n);
    graphs.push_back(tmp);
}

void Link(int a, int b) {
    adj[a].push_back(b);
    adj[b].push_back(a);
    graphs[0].add(a,b);
    if(graphs[0].maxi >= 3 && graphs.size() == 1){
        for(int i = 0;i<n;i++){
            if(adj[i].size() == 3){
                nodes.push_back(i);
                for(auto u:adj[i]){
                    nodes.push_back(u);
                }
                break;
            }
        }
        for(int j = 1;j<nodes.size();j++){
            DSU tmp(n);
            graphs.push_back(tmp);
            for(int i = 0;i<n;i++){
                if(i == nodes[j])continue;
                for(auto u:adj[i]){
                    if(u == nodes[j] || i > u)continue;
                    //cout << nodes[j] << " " << i << "  " << u << endl;
                    graphs[j].add(i,u);
                }
            }
        }
    }
    else if(graphs[0].maxi >= 3){
        for(int j = 1;j<nodes.size();j++){
            if(a == nodes[j] || b == nodes[j])continue;
            graphs[j].add(a,b);
        }
    }
}

int CountCritical() {
    if(graphs[0].maxi < 3){
        int ans = n;
        if(graphs[0].cycles.size() > 1)ans = 0;
        if(graphs[0].cycles.size() == 1)ans = graphs[0].cycles[0];
        return ans;
    }
    int ans = 0;
    for(int i = 1;i<nodes.size();i++){
        ans += (graphs[i].maxi < 3 && graphs[i].cycles.size() == 0);
    }
    return ans;
}

Compilation message

rings.cpp: In function 'void Link(int, int)':
rings.cpp:76:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for(int j = 1;j<nodes.size();j++){
      |                       ~^~~~~~~~~~~~~
rings.cpp:90:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         for(int j = 1;j<nodes.size();j++){
      |                       ~^~~~~~~~~~~~~
rings.cpp: In function 'int CountCritical()':
rings.cpp:105:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |     for(int i = 1;i<nodes.size();i++){
      |                   ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 16 ms 24312 KB Output is correct
3 Correct 17 ms 24404 KB Output is correct
4 Correct 14 ms 23812 KB Output is correct
5 Correct 14 ms 23892 KB Output is correct
6 Correct 15 ms 24020 KB Output is correct
7 Correct 13 ms 24176 KB Output is correct
8 Correct 15 ms 23928 KB Output is correct
9 Correct 15 ms 24404 KB Output is correct
10 Correct 15 ms 24432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 434 ms 50944 KB Output is correct
2 Correct 1824 ms 115616 KB Output is correct
3 Correct 2749 ms 151432 KB Output is correct
4 Correct 1054 ms 84152 KB Output is correct
5 Correct 1052 ms 84368 KB Output is correct
6 Correct 1033 ms 82680 KB Output is correct
7 Correct 2648 ms 149172 KB Output is correct
8 Correct 2064 ms 150552 KB Output is correct
9 Correct 2155 ms 161492 KB Output is correct
10 Correct 702 ms 82076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 16 ms 24312 KB Output is correct
3 Correct 17 ms 24404 KB Output is correct
4 Correct 14 ms 23812 KB Output is correct
5 Correct 14 ms 23892 KB Output is correct
6 Correct 15 ms 24020 KB Output is correct
7 Correct 13 ms 24176 KB Output is correct
8 Correct 15 ms 23928 KB Output is correct
9 Correct 15 ms 24404 KB Output is correct
10 Correct 15 ms 24432 KB Output is correct
11 Correct 18 ms 24404 KB Output is correct
12 Correct 18 ms 25112 KB Output is correct
13 Correct 17 ms 25044 KB Output is correct
14 Correct 17 ms 24876 KB Output is correct
15 Correct 18 ms 25812 KB Output is correct
16 Correct 18 ms 24300 KB Output is correct
17 Correct 18 ms 25232 KB Output is correct
18 Correct 19 ms 25916 KB Output is correct
19 Correct 16 ms 24304 KB Output is correct
20 Correct 19 ms 25016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 16 ms 24312 KB Output is correct
3 Correct 17 ms 24404 KB Output is correct
4 Correct 14 ms 23812 KB Output is correct
5 Correct 14 ms 23892 KB Output is correct
6 Correct 15 ms 24020 KB Output is correct
7 Correct 13 ms 24176 KB Output is correct
8 Correct 15 ms 23928 KB Output is correct
9 Correct 15 ms 24404 KB Output is correct
10 Correct 15 ms 24432 KB Output is correct
11 Correct 18 ms 24404 KB Output is correct
12 Correct 18 ms 25112 KB Output is correct
13 Correct 17 ms 25044 KB Output is correct
14 Correct 17 ms 24876 KB Output is correct
15 Correct 18 ms 25812 KB Output is correct
16 Correct 18 ms 24300 KB Output is correct
17 Correct 18 ms 25232 KB Output is correct
18 Correct 19 ms 25916 KB Output is correct
19 Correct 16 ms 24304 KB Output is correct
20 Correct 19 ms 25016 KB Output is correct
21 Correct 30 ms 25916 KB Output is correct
22 Correct 42 ms 27168 KB Output is correct
23 Correct 45 ms 28200 KB Output is correct
24 Correct 94 ms 34076 KB Output is correct
25 Correct 33 ms 33444 KB Output is correct
26 Correct 98 ms 34332 KB Output is correct
27 Correct 54 ms 28888 KB Output is correct
28 Correct 95 ms 36524 KB Output is correct
29 Correct 76 ms 34108 KB Output is correct
30 Correct 102 ms 29540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 16 ms 24312 KB Output is correct
3 Correct 17 ms 24404 KB Output is correct
4 Correct 14 ms 23812 KB Output is correct
5 Correct 14 ms 23892 KB Output is correct
6 Correct 15 ms 24020 KB Output is correct
7 Correct 13 ms 24176 KB Output is correct
8 Correct 15 ms 23928 KB Output is correct
9 Correct 15 ms 24404 KB Output is correct
10 Correct 15 ms 24432 KB Output is correct
11 Correct 434 ms 50944 KB Output is correct
12 Correct 1824 ms 115616 KB Output is correct
13 Correct 2749 ms 151432 KB Output is correct
14 Correct 1054 ms 84152 KB Output is correct
15 Correct 1052 ms 84368 KB Output is correct
16 Correct 1033 ms 82680 KB Output is correct
17 Correct 2648 ms 149172 KB Output is correct
18 Correct 2064 ms 150552 KB Output is correct
19 Correct 2155 ms 161492 KB Output is correct
20 Correct 702 ms 82076 KB Output is correct
21 Correct 18 ms 24404 KB Output is correct
22 Correct 18 ms 25112 KB Output is correct
23 Correct 17 ms 25044 KB Output is correct
24 Correct 17 ms 24876 KB Output is correct
25 Correct 18 ms 25812 KB Output is correct
26 Correct 18 ms 24300 KB Output is correct
27 Correct 18 ms 25232 KB Output is correct
28 Correct 19 ms 25916 KB Output is correct
29 Correct 16 ms 24304 KB Output is correct
30 Correct 19 ms 25016 KB Output is correct
31 Correct 30 ms 25916 KB Output is correct
32 Correct 42 ms 27168 KB Output is correct
33 Correct 45 ms 28200 KB Output is correct
34 Correct 94 ms 34076 KB Output is correct
35 Correct 33 ms 33444 KB Output is correct
36 Correct 98 ms 34332 KB Output is correct
37 Correct 54 ms 28888 KB Output is correct
38 Correct 95 ms 36524 KB Output is correct
39 Correct 76 ms 34108 KB Output is correct
40 Correct 102 ms 29540 KB Output is correct
41 Correct 214 ms 43644 KB Output is correct
42 Correct 889 ms 121928 KB Output is correct
43 Correct 417 ms 115776 KB Output is correct
44 Correct 1575 ms 144492 KB Output is correct
45 Correct 1838 ms 135668 KB Output is correct
46 Correct 713 ms 74768 KB Output is correct
47 Correct 910 ms 75668 KB Output is correct
48 Correct 953 ms 126284 KB Output is correct
49 Correct 678 ms 75356 KB Output is correct
50 Correct 728 ms 74948 KB Output is correct
51 Correct 474 ms 103084 KB Output is correct
52 Correct 1361 ms 129776 KB Output is correct
53 Correct 919 ms 125336 KB Output is correct
54 Correct 1813 ms 129768 KB Output is correct
55 Correct 2068 ms 132428 KB Output is correct