Submission #558492

# Submission time Handle Problem Language Result Execution time Memory
558492 2022-05-07T13:09:26 Z Yazan_Alattar Izlet (COI19_izlet) C++14
100 / 100
853 ms 61472 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 3007;
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;

vector <int> adj[M];
vector < pair <int,int> > edges;
int n, p[M], sz[M], a[M][M], col[M], cur;
bool vist[M];

int root(int x){
    while(x != p[x]){
        p[x] = p[p[x]];
        x = p[x];
    }
    return x;
}

void connect(int x, int y){
    if(root(x) == root(y)) return;
    adj[x].pb(y); adj[y].pb(x);
    edges.pb({x, y});

    x = root(x); y = root(y);
    if(sz[x] > sz[y]) swap(x, y);
    p[x] = y;
    sz[y] += sz[x];
    return;
}

bool check(int node, int p, int src1, int src2){
    if(a[node][src1] == a[node][src2]){
        col[src1] = col[node];
        return 1;
    }

    for(auto i : adj[node]) if(i != p && vist[i]) if(check(i, node, src1, src2)) return 1;
    return 0;
}

void dfs(int node, int p){
    vist[node] = 1;

    if(node == 1 || !check(p, node, node, p)) col[node] = ++cur;

    for(auto i : adj[node]) if(i != p) dfs(i, node);
    return;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> n;
    for(int i = 1; i <= n; ++i) p[i] = i, sz[i] = 1;

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            cin >> a[i][j];

    for(int val = 1; val <= 2; ++val)
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                if(a[i][j] == val) connect(i, j);

    dfs(1, 0);

    for(int i = 1; i <= n; ++i) cout << col[i] << " "; cout << endl;
    for(auto i : edges) cout << i.F << " " << i.S << endl;
    return 0;
}

Compilation message

izlet.cpp: In function 'int main()':
izlet.cpp:78:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   78 |     for(int i = 1; i <= n; ++i) cout << col[i] << " "; cout << endl;
      |     ^~~
izlet.cpp:78:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   78 |     for(int i = 1; i <= n; ++i) cout << col[i] << " "; cout << endl;
      |                                                        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 656 ms 35840 KB Output is correct
3 Correct 556 ms 35900 KB Output is correct
4 Correct 542 ms 35740 KB Output is correct
5 Correct 577 ms 35800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 516 ms 35976 KB Output is correct
2 Correct 850 ms 44232 KB Output is correct
3 Correct 853 ms 39488 KB Output is correct
4 Correct 826 ms 39632 KB Output is correct
5 Correct 594 ms 43232 KB Output is correct
6 Correct 708 ms 37956 KB Output is correct
7 Correct 529 ms 32228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 656 ms 35840 KB Output is correct
3 Correct 556 ms 35900 KB Output is correct
4 Correct 542 ms 35740 KB Output is correct
5 Correct 577 ms 35800 KB Output is correct
6 Correct 516 ms 35976 KB Output is correct
7 Correct 850 ms 44232 KB Output is correct
8 Correct 853 ms 39488 KB Output is correct
9 Correct 826 ms 39632 KB Output is correct
10 Correct 594 ms 43232 KB Output is correct
11 Correct 708 ms 37956 KB Output is correct
12 Correct 529 ms 32228 KB Output is correct
13 Correct 585 ms 37672 KB Output is correct
14 Correct 650 ms 61472 KB Output is correct
15 Correct 501 ms 53404 KB Output is correct
16 Correct 537 ms 57964 KB Output is correct
17 Correct 516 ms 59956 KB Output is correct
18 Correct 420 ms 53460 KB Output is correct
19 Correct 513 ms 53460 KB Output is correct
20 Correct 445 ms 53584 KB Output is correct
21 Correct 477 ms 54120 KB Output is correct
22 Correct 467 ms 53860 KB Output is correct
23 Correct 447 ms 54268 KB Output is correct
24 Correct 483 ms 60628 KB Output is correct
25 Correct 417 ms 53624 KB Output is correct