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"
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define maxn 100010
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define ll long long
#define ii pair<int,int>
using namespace std;
int maxdegree, mk[maxn];
vector<int> g[maxn], res, pres;
ii f;
void dfs_1(int u,int p,int d){
if( mk[u] ) return;
db(u)
pres.push_back(u);
mk[u] = 1;
f = max( f , { d , u } );
for( auto v : g[u] )
if( v != p )
dfs_1(v,u,d+1);
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
for(int i=0; i<q.size(); i++){
g[p[i]+1].push_back(q[i]+1);
g[q[i]+1].push_back(p[i]+1);
}
for(int i=1; i<=n; i++){
maxdegree = max( maxdegree , (int)g[i].size() );
res.push_back(0);
}
if( maxdegree <= 2 ){
f = { -1 , -1 };
fill(mk+1,mk+n+1,0);
dfs_1(1,1,0);
pres.clear();
fill(mk+1,mk+n+1,0);
dfs_1(f.s,f.s,0);
for(int i=0; i<pres.size(); i++){
if( i < a ){ res[pres[i]-1] = 1; continue; }
if( i < a + b ){ res[pres[i]-1] = 2; continue; }
res[pres[i]-1] = 3;
}
}
return res;
}
Compilation message (stderr)
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=0; i<q.size(); i++){
| ~^~~~~~~~~
split.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=0; i<pres.size(); i++){
| ~^~~~~~~~~~~~
# | 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... |