이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
const int mxN=2020;
vector <int> v[mxN], g[mxN];
bool Chk[mxN];
bool used[mxN];
int sub[mxN];
int msub[mxN];
int f[mxN], invf[mxN];
bool cmp1(int a, int b)
{
return sub[a]>sub[b];
}
void dfs1(int now, int pre)
{
sub[now]=1;
msub[now]=-1;
for(int nxt : v[now])
{
if(Chk[nxt] || nxt==pre) continue;
dfs1(nxt, now);
sub[now]+=sub[nxt];
if(msub[now]==-1) msub[now]=nxt;
else if(sub[msub[now]]<sub[nxt]) msub[now]=nxt;
}
}
void Solve(int N) {
for(int i=0;i<N;i++) f[i]=i;
random_shuffle(f, f+N);
for(int i=0;i<N;i++) invf[f[i]]=i;
v[0].push_back(1);
v[1].push_back(0);
for(int i=2;i<N;i++)
{
if(used[i]) continue;
int root=1;
for(int j=0;j<N;j++) Chk[j]=false;
int cnt=0;
while(true)
{
cnt++;
dfs1(root, -1);
int cent=root;
while(msub[cent]!=-1 && sub[msub[cent]]*2>sub[root]) cent=msub[cent];
for(int nxt : v[cent])
{
if(Chk[nxt] || sub[nxt]<sub[cent]) continue;
sub[nxt]=sub[root]-sub[cent];
}
g[cent].clear();
for(int nxt : v[cent]) if(!Chk[nxt]) g[cent].push_back(nxt);
sort(g[cent].begin(), g[cent].end(), cmp1);
if(g[cent].empty())
{
v[cent].push_back(i);
v[i].push_back(cent);
break;
}
bool par=true;
bool flag=false;
for(int j=0;j<g[cent].size();j++)
{
int nxt=g[cent][j];
int res=invf[Query(f[cent], f[nxt], f[i])];
if(res!=cent)
{
par=false;
if(res==i)
{
//printf("s1");
for(int k=0;k<v[cent].size();k++)
{
if(v[cent][k]==nxt)
{
v[cent][k]=i;
break;
}
}
for(int k=0;k<v[nxt].size();k++)
{
if(v[nxt][k]==cent)
{
v[nxt][k]=i;
break;
}
}
v[i].push_back(cent);
v[i].push_back(nxt);
flag=true;
}
else if(res==nxt)
{
root=nxt;
Chk[cent]=true;
}
else
{
for(int k=0;k<v[cent].size();k++) {if(v[cent][k]==nxt) {v[cent][k]=res; break;}}
for(int k=0;k<v[nxt].size();k++) {if(v[nxt][k]==cent) {v[nxt][k]=res; break;}}
v[res].push_back(cent);
v[res].push_back(nxt);
v[i].push_back(res);
v[res].push_back(i);
used[res]=true;
flag=true;
}
break;
}
}
if(flag) break;
if(par)
{
v[cent].push_back(i);
v[i].push_back(cent);
break;
}
}
}
for(int i=0;i<N;i++)
{
for(int nxt : v[i])
{
if(f[nxt]>f[i]) Bridge(f[i], f[nxt]);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In function 'void Solve(int)':
meetings.cpp:64:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int j=0;j<g[cent].size();j++)
| ~^~~~~~~~~~~~~~~
meetings.cpp:74:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int k=0;k<v[cent].size();k++)
| ~^~~~~~~~~~~~~~~
meetings.cpp:82:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int k=0;k<v[nxt].size();k++)
| ~^~~~~~~~~~~~~~
meetings.cpp:101:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int k=0;k<v[cent].size();k++) {if(v[cent][k]==nxt) {v[cent][k]=res; break;}}
| ~^~~~~~~~~~~~~~~
meetings.cpp:102:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for(int k=0;k<v[nxt].size();k++) {if(v[nxt][k]==cent) {v[nxt][k]=res; break;}}
| ~^~~~~~~~~~~~~~
# | 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... |