QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322063#4829. Mark on a Graphalexz1205Compile Error//C++142.9kb2024-02-06 09:06:002024-02-06 09:06:01

Judging History

你现在查看的是最新测评结果

  • [2024-02-06 09:06:01]
  • 评测
  • [2024-02-06 09:06:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;


// mark graph in O(n^2+mn)

// check graph
    // dfs

const int N = 1000;

vector<set<int>> pos; 
set<int> adj[N];

bool dfs(int x, int d = 1){
    if (d == 5){
        return 1;
    }
    set<int>* nums1 = &adj[i];
    set<int>* nums2 = &pos.back();
    set<int> next;
    auto i = nums1->begin();
    auto j = nums2->begin();
    while (i != nums1->end() && j != nums2->end()){
        if (*i == *j){
            next.insert(next.end(), *i);
            i ++;
            j ++;
        }else if (*i > *j){
            j ++;
        }else {
            i ++;
        }
    }
    pos.push_back(next);
    for (int v: next){
        if (dfs(v, d+1)) return 1;
    }
    pos.pop_back();
    return 0;
}

int main(){
    int n, m;
    cin >> n >> m;
    for (int x = 0; x < m; x ++){
        int a, b;
        cin >> a >> b;
        a --, b --;
        adj[a].insert(b);
        adj[b].insert(a);
    }
    for (int x = 0; x < n; x ++){
        pos.push_back(adj[x]);
        if (dfs(x)){
            cout << "ok" << endl;
            return 0;
        }
        pos.pop_back();
    }
    for (int x = 0; x < n; x ++){
        for (int y = x+1; y < n; y ++){
            if (adj[x].find(y) == adj[x].end()){
                continue;
            }
            set<int> nums;
            set<int> inter;
            set<int>* nums1 = &adj[x];
            set<int>* nums2 = &adj[y];
            auto i = nums1->begin();
            auto j = nums2->begin();
            while (i != nums1->end() || j != nums2->end()){
                if (i == nums1->end() || *i > *j){
                    nums.insert(*j);
                    j ++;
                }else if (j == nums2->end() || *i < *j){
                    nums.insert(*i);
                    i ++;
                }else {
                    nums.insert(*j);
                    inter.insert(*i);
                    i ++;
                    j ++;
                }
            }
            if (inter.empty()){
                continue;
            }
            if (nums.size()-1 < 2){
                continue;
            }
            vector<pair<int, int>> change;
            int a = *inter.begin();
            nums.erase(a);
            int b = *nums.begin();
            int c = *nums.rbegin();
            vector<int> test = {x, y, a, b, c};
            for (int x = 0; x < 5; x ++){
                for (int y = x+1; y < 5; y ++){
                    if (adj[test[x]].find(test[y]) == adj[test[x]].end()){
                        change.push_back({test[x], test[y]});
                    }
                }
            }
            cout << "mark" << endl;
            cout << change.size() << endl;
            for (pair<int, int> p: change){
                cout << p.first << " " << p.second << endl;
            }
            return 0;
        }
    }
}

Details

answer.code: In function ‘bool dfs(int, int)’:
answer.code:19:28: error: ‘i’ was not declared in this scope
   19 |     set<int>* nums1 = &adj[i];
      |                            ^