Submission #718680

# Submission time Handle Problem Language Result Execution time Memory
718680 2023-04-04T14:03:03 Z filipmihov Mostovi (COI14_mostovi) C++
30 / 100
12 ms 11604 KB
#include <bits/stdc++.h>

using namespace std;

bool l, visited[100002];
vector <vector <int> > v(100005);

vector <int> izbrisi (vector <int> r, int x)
{
    vector <int> t;
    for (int i=0; i<r.size(); i++)
        if (r[i] != x)
            t.push_back(r[i]);

    return t;
}

void dfs (int teme, int kraj)
{
    if (teme == kraj)
    {
        l = true;
        return;
    }

    visited[teme] = true;

    for (int i=0; i<v[teme].size(); i++)
        if (visited[v[teme][i]] == false)
    {
        dfs(v[teme][i], kraj);
        if (l==true)
            return;
    }
}

int main()
{
    int n, m;
    cin >> n >> m;

    for (int i=1; i<n; i++)
        v[i].push_back(i+1);

    for (int j=n+2; j<=2*n; j++)
        v[j].push_back(j-1);

    while (m--)
    {
        char x;
        cin >> x;

        if (x=='A')
        {
            int a,b;
            cin >> a >> b;

            v[a].push_back(b);
            v[b].push_back(a);
        }

        if (x=='B')
        {
            int a,b;
            cin >> a >> b;

            if (b <= n)
                if (a < b)
                    v[a] = izbrisi(v[a], b);
                else
                    v[b] = izbrisi(v[b], a);
            else
                if (a < b)
                    v[b] = izbrisi(v[b], a);
                else
                    v[a] = izbrisi(v[a], b);
        }

        if (x=='Q')
        {
            int a,b;
            cin >> a >> b;

            l = false;
            memset(visited,0,sizeof(visited));
            dfs(a, b);

            if (l==true)
                cout << "DA" << endl;
            else
                cout << "NE" << endl;
        }
    }
    return 0;
}

Compilation message

mostovi.cpp: In function 'std::vector<int> izbrisi(std::vector<int>, int)':
mostovi.cpp:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int i=0; i<r.size(); i++)
      |                   ~^~~~~~~~~
mostovi.cpp: In function 'void dfs(int, int)':
mostovi.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i=0; i<v[teme].size(); i++)
      |                   ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2772 KB Output is correct
2 Correct 7 ms 2772 KB Output is correct
3 Correct 4 ms 2808 KB Output is correct
4 Runtime error 11 ms 11548 KB Execution killed with signal 11
5 Runtime error 11 ms 11480 KB Execution killed with signal 11
6 Runtime error 12 ms 11476 KB Execution killed with signal 11
7 Runtime error 11 ms 11512 KB Execution killed with signal 11
8 Runtime error 12 ms 11512 KB Execution killed with signal 11
9 Runtime error 10 ms 11604 KB Execution killed with signal 11
10 Runtime error 12 ms 11508 KB Execution killed with signal 11