Submission #574957

# Submission time Handle Problem Language Result Execution time Memory
574957 2022-06-09T13:25:19 Z 1zaid1 Carnival (CEOI14_carnival) C++14
20 / 100
147 ms 10728 KB
#include <bits/stdc++.h>
using namespace std;
// #define endl '\n'
const int M = 2e5+5, MOD = 1000000007;
#define int long long
int rnk[M], clr[M], p[M];

set<int> nono[M];

int find(int s) {
    return (s == p[s]?s:p[s]=find(p[s]));
}

void uni(int a, int b) {
    if (rnk[a] < rnk[b]) swap(a, b);
    if (rnk[a] == rnk[b]) rnk[a]++;
    p[b] = a;
    clr[a] = min(clr[a], clr[b]);

    for (int j:nono[b]) nono[a].insert(j);
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);

    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) clr[i] = p[i] = i;

    for (int i=1;i<=n;i++) {
        for(int j=i+1;j<=n;j++) {
            bool check = 1;
            for (int k:nono[j]) {
                if (find(i) == find(k)) check = 0;
            }

            for (int k:nono[i]) {
                if (find(j) == find(k)) check = 0;
            }

            if (find(i) != find(j) && check) {
                cout << 2 << ' ' << i << ' ' << j << endl;
                int x;
                cin >> x;

                if (x == 1) uni(find(i), find(j));
                else {
                    nono[find(i)].insert(find(j));
                    nono[find(j)].insert(find(i));
                }
            }
        }
    }

    map<int, int> mp;
    set<int> st;
    for (int i = 1; i <= n; i++) st.insert(find(i));
    int cnt = 1;
    for (int i:st) mp[i] = cnt++;

    cout << 0 << ' ';
    for (int i = 1; i <= n; i++) cout << mp[clr[find(i)]] << ' '; cout << endl;

    return 0;
}
/*
3 
0 3 0
3 0 0
5 4 0

3
1 1 1
3 0 1
4 5 1
*/

Compilation message

carnival.cpp: In function 'int main()':
carnival.cpp:63:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   63 |     for (int i = 1; i <= n; i++) cout << mp[clr[find(i)]] << ' '; cout << endl;
      |     ^~~
carnival.cpp:63:67: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   63 |     for (int i = 1; i <= n; i++) cout << mp[clr[find(i)]] << ' '; cout << endl;
      |                                                                   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 9680 KB Output is correct
2 Correct 26 ms 9808 KB Output is correct
3 Partially correct 75 ms 10244 KB Partially correct
4 Partially correct 107 ms 10500 KB Partially correct
5 Correct 8 ms 9740 KB Output is correct
6 Correct 6 ms 9728 KB Output is correct
7 Correct 23 ms 9776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9680 KB Output is correct
2 Correct 31 ms 9900 KB Output is correct
3 Partially correct 33 ms 10108 KB Partially correct
4 Partially correct 84 ms 10468 KB Partially correct
5 Correct 8 ms 9676 KB Output is correct
6 Correct 7 ms 9732 KB Output is correct
7 Correct 14 ms 9776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9736 KB Output is correct
2 Correct 12 ms 9752 KB Output is correct
3 Partially correct 53 ms 10060 KB Partially correct
4 Partially correct 79 ms 10624 KB Partially correct
5 Correct 12 ms 9680 KB Output is correct
6 Correct 15 ms 9820 KB Output is correct
7 Correct 23 ms 9860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9740 KB Output is correct
2 Correct 11 ms 9756 KB Output is correct
3 Partially correct 101 ms 10392 KB Partially correct
4 Partially correct 136 ms 10728 KB Partially correct
5 Correct 11 ms 9812 KB Output is correct
6 Correct 43 ms 9908 KB Output is correct
7 Correct 18 ms 9852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9736 KB Output is correct
2 Correct 22 ms 9816 KB Output is correct
3 Partially correct 75 ms 10168 KB Partially correct
4 Partially correct 80 ms 10340 KB Partially correct
5 Correct 29 ms 9988 KB Output is correct
6 Partially correct 81 ms 10240 KB Partially correct
7 Partially correct 147 ms 10604 KB Partially correct