# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1080572 | Evirir | City (JOI17_city) | C++17 | 3004 ms | 41660 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Encoder.h"
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define cbug if(DEBUG) cout
#define setp(x) cout<<fixed<<setprecision(x)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
static constexpr ll LG = 18;
static constexpr ll MAXN = 250000;
static vector<vector<int>> adj;
static int tmr = 0;
static vector<ll> in;
static vector<ll> out;
static vector<int> prt, sub;
void getprt(int u, int p = -1)
{
sub[u] = 1;
prt[u] = p;
for (const auto v : adj[u])
{
if (v == p) continue;
getprt(v, u);
sub[u] += sub[v];
}
}
void dfs(int u, int p = -1)
{
in[u] = tmr;
if (adj[u].empty())
{
out[u] = tmr;
return;
}
for (const auto v : adj[u])
{
dfs(v, u);
tmr++;
}
tmr--;
if (sz(adj[u]) == 1)
{
tmr++;
out[u] = tmr;
return;
}
out[u] = tmr;
}
ll arith(ll l, ll r)
{
return (l + r) * (r - l + 1) / 2;
}
ll pair2id(ll l, ll r)
{
l++; r++;
return arith(MAXN - (l - 1) + 1, MAXN) + r - l + 1; // pair id 1-indexed
}
void Encode(int n, int a[], int b[])
{
adj.resize(n);
in.resize(n);
out.resize(n);
prt.resize(n, -1);
sub.resize(n);
forn(i,0,n-1)
{
adj[a[i]].pb(b[i]);
adj[b[i]].pb(a[i]);
}
getprt(0);
forn(u,1,n)
{
forn(i,0,sz(adj[u]))
{
if (adj[u][i] == prt[u])
{
swap(adj[u][i], adj[u].back());
adj[u].pop_back();
break;
}
}
sort(all(adj[u]), [](int v1, int v2){ return tie(sub[v1], v1) > tie(sub[v2], v2); });
}
dfs(0);
forn(u,0,n)
{
ll c = pair2id(in[u], out[u]);
Code(u, c);
}
}
#include "Device.h"
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define cbug if(DEBUG) cout
#define setp(x) cout<<fixed<<setprecision(x)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
static constexpr int LG = 18;
static constexpr int MAXN = 250000;
void InitDevice()
{
}
static pair<ll, ll> id2pair(ll s)
{
ll sum = 0;
fore(i,1,MAXN)
{
ll newsum = sum + (MAXN - i + 1);
if (newsum >= s)
{
ll in = i;
ll rem = s - sum;
ll out = in - 1 + rem;
return {in, out};
}
sum = newsum;
}
assert(0);
return {};
}
int Answer(long long s, long long t)
{
auto [s1, t1] = id2pair(s);
auto [s2, t2] = id2pair(t);
if (s2 <= s1 && t1 <= t2) return 0;
if (s1 <= s2 && t2 <= t1) return 1;
return 2;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |