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 "split.h"
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<long> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
vvi paths(100005,vi());
vi ans,lengths;
void dfs(int pos,int prev,int counter,int type){
// cout << pos << " " << counter << " " << type << endl;
if(type == 3)return;
ans[pos] = type+1;
counter++;
if(counter == lengths[type]){
type++;
counter = 0;
}
for(int node:paths[pos]){
if(node == prev)continue;
dfs(node,pos,counter,type);
}
}
vector<int> find_split(int n, int a, int b, int c, vi p, vi q) {
lengths = {a,b,c};
FOR(i,0,p.size()){
paths[p[i]].pb(q[i]);
paths[q[i]].pb(p[i]);
}
int head = 0;
FOR(i,0,n){
if(paths[i].size()==1){
head = i;
break;
}
}
ans = vi(n,0);
dfs(head,-1,0,0);
return ans;
}
Compilation message (stderr)
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, vi, vi)':
split.cpp:22:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | #define FOR(i, a, b) for (int i = a; i < (b); i++)
| ^
split.cpp:62:2: note: in expansion of macro 'FOR'
62 | FOR(i,0,p.size()){
| ^~~
# | 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... |