이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//------------------------------------\\
// ------------------------------ \\
// | created by Dinh Manh Hung | \\
// | tht.onepunchac168 | \\
// | THPT CHUYEN HA TINH | \\
// | HA TINH, VIET NAM | \\
// | Siuuu | \\
// ------------------------------ \\
//------------------------------------\\
#include <bits/stdc++.h>
using namespace std;
#define task ""
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define ldb long double
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) begin(x),end(x)
#define uniquev(v) v.resize(unique(all(v))-v.begin())
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define cntbit(v) __builtin_popcountll(v)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((1LL*a*b)/__gcd(a,b))
#define mask(x) (1LL<<(x))
#define readbit(x,i) ((x>>i)&1)
#define Yes cout << "Yes"
#define YES cout << "YES"
#define No cout << "No"
#define NO cout << "NO"
typedef long long ll;
typedef pair <ll,ll> ii;
typedef pair <ll,ii> iii;
typedef pair <ii,ii> iiii;
ll dx[]= {1,-1,0,0,1,-1,1,-1};
ll dy[]= {0,0,-1,1,1,-1,-1,1};
const ldb PI = acos (-1);
//const ll mod=978846151;
//const ll base=29;
const ll mod=1e9+7;
const char nl = '\n';
inline int ReadInt()
{
char co;
for (co = getchar(); co < '0' || co > '9'; co = getchar());
int xo = co - '0';
for (co = getchar(); co >= '0' && co <= '9'; co = getchar())
xo = (xo<<1) + (xo<<3) + co - '0';
return xo;
}
void WriteInt(int xo)
{
if (xo > 9)
WriteInt(xo / 10);
putchar(xo % 10 + '0');
}
// DEBUG
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/* END OF TEMPLATE*/
// ================= Solution =================//
/*
void onepunchac168();
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
file(task);
int tests;
tests=1;
//cin>>tests;
while (tests--)
{
onepunchac168();
}
}
const int N=2e5+5;
void onepunchac168()
{
}
*/
// goodbye see ya
const int N=3e5+5;
struct DSU{
int lab[N];
void makeset(int u)
{
lab[u]=-1;
}
int findset(int u)
{
if (lab[u]<0)
{
return u;
}
return lab[u]=findset(lab[u]);
}
void Union(int r,int s)
{
lab[r]=s;
}
} dsu;
int raz[N];
int n;
int pos[N];
bool check[N];
vector <ii> vt[N];
vector <int > color[N];
queue< int > qu;
bool fee[N];
bool check_color[N];
vector <int > ss;
int kq=1e9+5;
vector <int > res;
void solve(int start,int pp)
{
pos[start]=pp;
while (!qu.empty())
{
qu.pop();
}
qu.push(start);
ss.pb(raz[start]);
vector <int > gg;
while (!qu.empty())
{
int u=qu.front();
qu.pop();
if (dsu.findset(u)!=start)
{
pos[dsu.findset(u)]=pp;
dsu.Union(start,dsu.findset(u));
return;
}
if (fee[u]==0)
{
gg.pb(u);
fee[u]=1;
}
else continue;
if (check_color[raz[u]]==0)
{
check_color[raz[u]]=1;
for (auto v:color[raz[u]])
{
qu.push(v);
}
}
for (auto v:vt[u])
{
if (check_color[v.se]==1)
{
ss.pb(raz[v.fi]);
qu.push(v.fi);
}
else
{
color[v.se].pb(v.fi);
ss.pb(v.se);
}
}
}
check[start]=1;
//cout<<start<<" "<<gg.size()<<" === "<<nl;
if (kq>gg.size())
{
res.clear();
kq=gg.size();
}
if (kq==gg.size())
{
for (auto v:gg)
{
res.pb(v);
}
}
}
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) {
std::vector<int> ans(r.size(),0);
n=r.size();
for (int i=1;i<=n;i++)
{
raz[i]=r[i-1]+1;
dsu.makeset(i);
}
for (int i=0;i<u.size();i++)
{
u[i]++;
v[i]++;
c[i]++;
vt[u[i]].pb({v[i],c[i]});
vt[v[i]].pb({u[i],c[i]});
}
ll id=0;
while (true)
{
id++;
bool ck=true;
for (int i=1;i<=n;i++)
{
fee[i]=0;
}
for (int i=1;i<=n;i++)
{
if (dsu.lab[i]==-1&&pos[i]!=id&&check[i]==0)
{
ck=false;
solve(i,id);
for (auto v:ss)
{
check_color[v]=0;
color[v].clear();
}
ss.clear();
}
}
if (ck==true)
{
break;
}
}
for (auto v:res)
{
ans[v-1]=1;
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
keys.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //------------------------------------\\
| ^
keys.cpp: In function 'void solve(int, int)':
keys.cpp:210:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
210 | if (kq>gg.size())
| ~~^~~~~~~~~~
keys.cpp:215:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
215 | if (kq==gg.size())
| ~~^~~~~~~~~~~
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:232:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
232 | for (int i=0;i<u.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... |