# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
760625 | Magikarp4000 | Stray Cat (JOI20_stray) | C++17 | 0 ms | 0 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 "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n'
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
const int pat[] = {1,1,0,1,0,0};
const int MAXN = 2e4+1;
int n,m;
vector<PII> v[MAXN];
int p[MAXN], pr[MAXN];
vector<int> res;
namespace {
void dfs(int s, int pa) {
if (s != 0 && v[s].size() >= 3) {
int c = res[pr[s]] == 1 ? 0 : 1;
FORX(u,v[s]) {
if (u.F == pa) continue;
res[u.S] = c;
}
if (res[pr[s]] == -1) res[pr[s]] = 0;
}
FORX(u,v[s]) {
if (u.F == pa) continue;
pr[u.F] = s;
pr[u.F] = u.S;
dfs(u.F,s);
}
}
void dfs1(int s, int pa, int idx) {
FORX(u,v[s]) {
if (u.F == pa) continue;
int nc = idx;
if ((s == 0 || v[s].size() == 2) && res[u.S] == -1) {
res[u.S] = pat[idx];
nc = (idx+1)%6;
}
if (v[s].size() >= 3) nc = 0;
dfs1(u.F,s,nc);
}
}
} // namespace
std::vector<int> Mark(int N, int M, int A, int B, std::vector<int> U, std::vector<int> V) {
n = N; m = M;
FOR(i,0,m) {
v[U[i]].PB({V[i],i});
v[V[i]].PB({U[i],i});
}
FOR(i,0,m) res.PB(-1);
dfs(0,-1);
dfs1(0,-1,0);
return res;
}
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n'
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
const int pat[] = {1,1,0,1,0,0};
const int MAXN = 2e4+1;
int n,m;
vector<PII> v[MAXN];
int p[MAXN], pr[MAXN];
vector<int> res;
namespace {
void dfs(int s, int pa) {
if (s != 0 && v[s].size() >= 3) {
int c = res[pr[s]] == 1 ? 0 : 1;
FORX(u,v[s]) {
if (u.F == pa) continue;
res[u.S] = c;
}
if (res[pr[s]] == -1) res[pr[s]] = 0;
}
FORX(u,v[s]) {
if (u.F == pa) continue;
pr[u.F] = s;
pr[u.F] = u.S;
dfs(u.F,s);
}
}
void dfs1(int s, int pa, int idx) {
FORX(u,v[s]) {
if (u.F == pa) continue;
int nc = idx;
if ((s == 0 || v[s].size() == 2) && res[u.S] == -1) {
res[u.S] = pat[idx];
nc = (idx+1)%6;
}
if (v[s].size() >= 3) nc = 0;
dfs1(u.F,s,nc);
}
}
} // namespace
std::vector<int> Mark(int N, int M, int A, int B, std::vector<int> U, std::vector<int> V) {
n = N; m = M;
FOR(i,0,m) {
v[U[i]].PB({V[i],i});
v[V[i]].PB({U[i],i});
}
FOR(i,0,m) res.PB(-1);
dfs(0,-1);
dfs1(0,-1,0);
return res;
}