Submission #558487

# Submission time Handle Problem Language Result Execution time Memory
558487 2022-05-07T13:02:39 Z Yazan_Alattar Izlet (COI19_izlet) C++14
18 / 100
580 ms 36600 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){
    x = root(x); y = root(y);
    if(x == y) return;

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

    adj[x].pb(y); adj[y].pb(x);
    edges.pb({x, y});
    return;
}

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

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

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:80:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   80 |     for(int i = 1; i <= n; ++i) cout << col[i] << " "; cout << endl;
      |     ^~~
izlet.cpp:80:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   80 |     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 580 ms 36368 KB Output is correct
3 Correct 536 ms 36396 KB Output is correct
4 Correct 489 ms 36600 KB Output is correct
5 Correct 543 ms 36584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 440 ms 35932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 580 ms 36368 KB Output is correct
3 Correct 536 ms 36396 KB Output is correct
4 Correct 489 ms 36600 KB Output is correct
5 Correct 543 ms 36584 KB Output is correct
6 Incorrect 440 ms 35932 KB Output isn't correct
7 Halted 0 ms 0 KB -