Submission #1013700

# Submission time Handle Problem Language Result Execution time Memory
1013700 2024-07-03T21:38:52 Z ThegeekKnight16 Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
vector<int> pai, sub;

int find(int v) {return pai[v] = (pai[v] == v ? v : find(pai[v]));}
void une(int x, int y)
{
    x = find(x); y = find(y);
    if (x == y) return;
    if (sub[x] < sub[y]) swap(x, y);
    pai[y] = x;
    sub[x] += sub[y];
}


std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v)
{
    int M = u.size();
    vector<int> Marc(M);
    vector<int> good;
    for (int i = 0; i < M && good.size() < n-1; i++)
    {
        if (Marc[i]) continue;
        int U = u[i], V = v[i];
        pai.resize(n); sub.resize(n);
        iota(pai.begin(), pai.end(), 0);
        fill(sub.begin(), sub.end(), 1);
        for (auto j : good) une(u[j], v[j]);
        if (find(U) == find(V)) continue;
        vector<int> r; vector<int> poss;
        for (int j = 0; j < M; j++)
        {
            if (Marc[j]) continue;
            int X = u[j], Y = v[j];
            if (find(X) == find(Y)) continue;
            if ((find(X) == find(U) && find(Y) == find(V)) || (find(X) == find(V) && find(Y) == find(U)))
            {
                poss.push_back(j);
                Marc[j] = 1;
                continue;
            }
            une(X, Y); r.push_back(j);
        }
        if (poss.size() == 1) {good.push_back(i); continue;}
        vector<int> res(poss.size());
        for (int i = 0; i < poss.size(); i++)
        {
            r.push_back(i);
            res[i] = count_common_roads(r);
            r.pop_back();
        }
        int x = *max_element(res.begin(), res.end());
        for (int i = 0; i < poss.size(); i++) if (res[i] == x) good.push_back(poss[i]);
    }
    return good;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:22:42: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |     for (int i = 0; i < M && good.size() < n-1; i++)
      |                              ~~~~~~~~~~~~^~~~~
simurgh.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int i = 0; i < poss.size(); i++)
      |                         ~~^~~~~~~~~~~~~
simurgh.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int i = 0; i < poss.size(); i++) if (res[i] == x) good.push_back(poss[i]);
      |                         ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB correct
2 Incorrect 0 ms 344 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -