#include "worldmap.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9;
vi graph[41];
vi route;
bool odw[41];
int val[41];
pii change_dig[41];
void dfs(int v)
{
route.pb(v);
odw[v] = 1;
forall(it,graph[v])
{
if(odw[it] == 0)
{
dfs(it);
route.pb(v);
}
}
}
vector<vi> create_map(int n, int m, vi A, vi B)
{
rep(i,n) graph[i+1] = {};
rep(i,m)
{
graph[A[i]].pb(B[i]);
graph[B[i]].pb(A[i]);
}
route = {};
rep2(i,1,n) odw[i] = 0;
dfs(1);
rep2(i,1,n) odw[i] = 0;
vector<pll> v_sort;
pii cur_beg = {0,0};
vector<vi> ans(n*2,vi(n*2,0));
forall(it,route)
{
if(odw[it] == 0)
{
pii poz = cur_beg;
while(poz.ff != -1 && poz.ss != n*2)
{
ans[poz.ff][poz.ss] = it;
poz.ff--;
poz.ss++;
}
int len = 0;
if(cur_beg.ff != n*2-1) cur_beg.ff++;
else cur_beg.ss++;
poz = cur_beg;
change_dig[it] = cur_beg;
while(poz.ff != -1 && poz.ss != n*2)
{
ans[poz.ff][poz.ss] = it;
poz.ff--;
poz.ss++;
len++;
}
v_sort.pb({len,it});
if(cur_beg.ff != n*2-1) cur_beg.ff++;
else cur_beg.ss++;
poz = cur_beg;
while(poz.ff != -1 && poz.ss != n*2)
{
ans[poz.ff][poz.ss] = it;
poz.ff--;
poz.ss++;
}
odw[it] = 1;
}
else
{
pii poz = cur_beg;
while(poz.ff != -1 && poz.ss != n*2)
{
ans[poz.ff][poz.ss] = it;
poz.ff--;
poz.ss++;
}
}
if(cur_beg.ff != n*2-1) cur_beg.ff++;
else cur_beg.ss++;
}
sort(all(v_sort));
rep(i,n) val[v_sort[i].ss] = i;
rep(i,m)
{
if(val[A[i]] < val[B[i]]) swap(A[i],B[i]);
ans[change_dig[A[i]].ff][change_dig[A[i]].ss] = B[i];
change_dig[A[i]].ff--;
change_dig[A[i]].ss++;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |