Submission #158957

# Submission time Handle Problem Language Result Execution time Memory
158957 2019-10-19T16:25:21 Z georgerapeanu Meetings (JOI19_meetings) C++17
0 / 100
296 ms 1068 KB
#include "meetings.h"
#pragma once
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

map<pair<int,int>,int> asked;
int lvl[2005];

int my_query(int u,int v,int w){
    u--;
    v--;
    w--;

    if(v == u || w == u){
        return u + 1;
    }

    if(v == w){
        return v + 1;
    }

    printf("%d %d %d\n",u,v,w);

    return Query(u,v,w) + 1;
}

void my_bridge(int u,int v){
    u--;
    v--;
    if(u > v){
        swap(u,v);
    }
    printf("%d %d\n",u,v);
    Bridge(u,v);
}

void solve(int root,vector<int> &nodes){
    for(int i = 0;i < (int)nodes.size();i++){
        if(nodes[i] == root){
            swap(nodes[i],nodes.back());
            nodes.pop_back();
            break;
        }
    }
    
    if(nodes.size() == 0){
        return;
    }
    if(nodes.size() == 1){
        my_bridge(root,nodes[0]);
        return ;
    }

    int node = nodes[rand() % (int)nodes.size()];

    vector<int> path = {root,node};

    map<int,vector<int> > subseq;

    for(auto it:nodes){
        int tmp = my_query(root,it,node);
        if(tmp != node){
            path.push_back(tmp);
        }
        subseq[tmp].push_back(it);
    }

    sort(path.begin(),path.end(),[&](int a,int b){return my_query(root,a,b) == a;});

    for(int i = 1;i < (int)path.size();i++){
        subseq[path[i - 1]].erase(find(subseq[path[i - 1]].begin(),subseq[path[i - 1]].end(),path[i]));
        my_bridge(path[i - 1],path[i]);
    }

    for(auto it:subseq){
        solve(it.first,it.second);
    }
}

void Solve(int N) {
    srand(time(NULL));
    vector<int> nodes;
    for(int i = 1;i <= N;i++){
        nodes.push_back(i);
    }
    solve(1,nodes);
}

Compilation message

meetings.cpp:2:9: warning: #pragma once in main file
 #pragma once
         ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 296 ms 1068 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -