답안 #718641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718641 2023-04-04T13:02:57 Z filipmihov Mostovi (COI14_mostovi) C++
0 / 100
14 ms 11552 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+1; 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 (a < b)
                v[a] = izbrisi(v[a], b);
            else
                v[b] = izbrisi(v[b], a);
        }

        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++)
      |                   ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2772 KB Output isn't correct
2 Incorrect 11 ms 2772 KB Output isn't correct
3 Incorrect 5 ms 2772 KB Output isn't correct
4 Runtime error 10 ms 11464 KB Execution killed with signal 11
5 Runtime error 11 ms 11552 KB Execution killed with signal 11
6 Runtime error 10 ms 11476 KB Execution killed with signal 11
7 Runtime error 14 ms 11476 KB Execution killed with signal 11
8 Runtime error 11 ms 11460 KB Execution killed with signal 11
9 Runtime error 14 ms 11488 KB Execution killed with signal 11
10 Runtime error 12 ms 11464 KB Execution killed with signal 11