답안 #878683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878683 2023-11-25T05:08:22 Z Ghulam_Junaid One-Way Streets (CEOI17_oneway) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
int n, m, p, deg[N];
int out[N], in[N];

vector<int> g[N], paired[N];
set<int> waiting_in[N], waiting_out[N];
map<pair<int, int>, int> edge;
vector<pair<int, int>> edges;

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

    string s;
    for (int i=0; i<m; i++){
        int u, v;
        cin >> u >> v;

        if (u != v){
            g[u].push_back(v);
            g[v].push_back(u);
            deg[u]++;
            deg[v]++;
            edge[{u, v}] = edge[{v, u}] = i;
        }
        edges.push_back({u, v});

        s += 'B';
    }

    cin >> p;
    for (int i=0; i<p; i++){
        int u, v;
        cin >> u >> v;

        out[u]++;
        in[v]++;

        // paired[v].push_back(u);
        // paired[u].push_back(v);

        waiting_in[v].insert(u);
        waiting_out[u].insert(v);
    }

    queue<int> q;
    for (int i=1; i<=n; i++)
        if (deg[i] == 1)
            q.push(i);

    while (!q.empty()){
        int v = q.front();
        deg[u]--;

        if (deg[v] != 1)
            continue;
        deg[v]--;

        int u = g[v][0];
        q.pop();

        int id = edge[{v, u}];

        // cout << v << " prev char = " << s[id] << " new char = ";

        // cout << "id = " << id << endl;

        if (waiting_in[v].size()){
            // cout << "here 1" << endl;
            if (edges[id].first == u)
                s[id] = 'R';
            else
                s[id] = 'L';

            if (deg[u] == 1)
                q.push(u);

            for (int x : waiting_in[v]){
                waiting_out[x].erase(v);
                if (x == u) continue;
                waiting_in[u].insert(x);
                waiting_out[x].insert(u);
            }
            waiting_in[v].clear();
        }
        else if (waiting_out[v].size()){
            // cout << "here 2" << endl;
            if (edges[id].first == v)
                s[id] = 'R';
            else
                s[id] = 'L';

            if (deg[u] == 1)
                q.push(u);

            for (int x : waiting_out[v]){
                waiting_in[x].erase(v);
                if (u == x) continue;
                waiting_out[u].insert(x);
                waiting_in[x].insert(u);
            }
            waiting_out[v].clear();
        }
        else{
            if (deg[u] == 1)
                q.push(u);
        }

        // cout << s[id] << endl;
    }

    cout << s << endl;
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:55:13: error: 'u' was not declared in this scope
   55 |         deg[u]--;
      |             ^
oneway.cpp:64:22: error: no match for 'operator[]' (operand types are 'std::map<std::pair<int, int>, int>' and '<brace-enclosed initializer list>')
   64 |         int id = edge[{v, u}];
      |                      ^
In file included from /usr/include/c++/10/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from oneway.cpp:1:
/usr/include/c++/10/bits/stl_map.h:492:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::pair<int, int>]'
  492 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:492:34: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const key_type&' {aka 'const std::pair<int, int>&'}
  492 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_map.h:512:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::pair<int, int>]'
  512 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:512:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::map<std::pair<int, int>, int>::key_type&&' {aka 'std::pair<int, int>&&'}
  512 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~