QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322072#4829. Mark on a Graphalexz12050 4ms3980kbC++144.2kb2024-02-06 09:47:542024-02-06 09:47:55

Judging History

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

  • [2024-02-06 09:47:55]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:3980kb
  • [2024-02-06 09:47:54]
  • 提交

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 3980kb

input:

1000 3560
603 151
415 20
102 569
895 552
678 734
24 614
689 518
440 223
751 919
223 433
711 551
502 634
706 583
812 501
514 535
780 751
720 530
532 384
888 139
864 791
292 675
171 881
30 592
464 557
280 299
654 650
894 335
250 532
792 10
83 969
118 771
579 300
852 983
243 940
957 939
817 889
911 319...

output:

mark
5
946 3
12 208
12 519
946 519
946 12

input:

1000 3565
626 777
295 222
665 811
534 33
682 101
107 833
155 950
656 183
184 217
383 221
676 187
815 771
335 355
759 167
640 763
707 250
342 897
224 881
974 22
521 228
368 12
794 262
113 210
639 831
511 688
95 125
440 102
70 757
464 840
11 36
355 37
232 687
790 201
990 267
201 580
617 583
221 937
25...

output:

mark
5
994 3
35 671
35 821
994 821
994 35

result:

wrong answer Token "mark" doesn't correspond to pattern "ok"