이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef pair <int,int> ii;
vector <int> ans(100005);
vector <int> fnl(100005);
vector <bool> v;
int edge=-1;
int node1=-1;
int node2=-1;
int N;
int A,B,C;
vector <vector <ii> > graph(100005);
int DFS(int node, int par=-1)
{
v[node]=1;
int sum=1;
for(int i=0;i<graph[node].size();i++)
{
if(v[graph[node][i].first]==0 && graph[node][i].first!=par)
{
int res=DFS(graph[node][i].first,node);
sum+=res;
ans[graph[node][i].second]=res;
if(res>=A && N-res>=B)
{
node1=graph[node][i].first;
node2=node;
edge=graph[node][i].second;
}
if(N-res>=A && res>=B)
{
node2=graph[node][i].first;
node1=node;
edge=graph[node][i].second;
}
}
}
return sum;
}
int k;
int u;
void DFS2(int node, int par, int cl)
{
v[node]=1;
fnl[node]=cl;
k++;
for(int i=0;k<u && i<graph[node].size();i++)
{
if(v[graph[node][i].first]==0 && graph[node][i].first!=par)
{
DFS2(graph[node][i].first,node,cl);
}
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q)
{
int small=a;
int mid=b;
int large=c;
int remap[]={1,2,3};
if(a>b)
{
swap(a,b);
swap(remap[0],remap[1]);
}
if(b>c)
{
swap(c,b);
swap(remap[2],remap[1]);
}
if(a>b)
{
swap(a,b);
swap(remap[0],remap[1]);
}
N=n;
A=a;
B=b;
C=c;
int m=p.size();
for(int i=0;i<m;i++)
{
graph[p[i]].pb(ii(q[i],i));
graph[q[i]].pb(ii(p[i],i));
}
v=vector <bool> (n,0);
DFS(0);
if(node1==-1)
{
return vector <int> (n,0);
}
fnl=vector <int> (n,remap[2]);
k=0;
u=A;
v=vector <bool> (n,0);
DFS2(node1,node2,remap[0]);
k=0;
u=B;
DFS2(node2,node1,remap[1]);
return fnl;
}
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'int DFS(int, int)':
split.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i=0;i<graph[node].size();i++)
| ~^~~~~~~~~~~~~~~~~~~
split.cpp: In function 'void DFS2(int, int, int)':
split.cpp:75:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int i=0;k<u && i<graph[node].size();i++)
| ~^~~~~~~~~~~~~~~~~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:87:6: warning: unused variable 'small' [-Wunused-variable]
87 | int small=a;
| ^~~~~
split.cpp:88:6: warning: unused variable 'mid' [-Wunused-variable]
88 | int mid=b;
| ^~~
split.cpp:89:6: warning: unused variable 'large' [-Wunused-variable]
89 | int large=c;
| ^~~~~
# | 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... |