이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<P> vp;
typedef vector<vp> vvp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define fi first
#define se second
#define pb emplace_back
#define all(a) a.begin(),a.end()
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
ll n=r.size(),m=u.size();
vi ord(n);rep(i,n)ord[i]=i;random_shuffle(all(ord));
vi seen1(n,-1),seen2(n,-1);
vb done(n,false),ok_c(n,false);
vvp g(n);
vvi edges(n);
rep(i,m){
g[u[i]].pb(v[i],c[i]);
g[v[i]].pb(u[i],c[i]);
}
vi p(n,n+1);
ll cnt_seen1=-1,cnt_seen2=-1;
for(ll s:ord)if(seen1[s]==-1){
vi tmp_c,tmp;
cnt_seen1++;
function<bool(ll)> dfs1=[&](ll i){
tmp.pb(i);
if(seen1[i]!=-1&&seen1[i]<cnt_seen1)return false;
seen1[i]=cnt_seen1;
if(!ok_c[r[i]]){
tmp_c.pb(r[i]);
ok_c[r[i]]=true;
for(ll x:edges[r[i]])if(seen1[x]!=cnt_seen1){
if(!dfs1(x))return false;
}
}
for(auto x:g[i])if(seen1[x.fi]!=cnt_seen1){
if(ok_c[x.se]){
if(!dfs1(x.fi))return false;
}
else{
edges[x.se].pb(x.fi);
}
}
return true;
};
bool res=dfs1(s);
// out(s);outv(tmp);
for(ll x:tmp_c){
edges[x].clear();
ok_c[x]=false;
}tmp_c.clear();
if(res){
random_shuffle(all(tmp));
done[s]=true;
ll idx=0;
while(idx<tmp.size()){
ll t=tmp[idx];
if(done[t]){
idx++;continue;
}
vi al;
cnt_seen2++;
function<bool(ll)> dfs2=[&](ll i){
al.pb(i);
if(done[i])return false;
seen2[i]=cnt_seen2;
if(!ok_c[r[i]]){
tmp_c.pb(r[i]);
ok_c[r[i]]=true;
for(ll x:edges[r[i]])if(seen2[x]!=cnt_seen2){
if(!dfs2(x))return false;
}
}
for(auto x:g[i])if(seen2[x.fi]!=cnt_seen2){
if(ok_c[x.se]){
if(!dfs2(x.fi))return false;
}
else{
edges[x.se].pb(x.fi);
}
}
return true;
};
for(ll x:tmp_c){
edges[x].clear();
ok_c[x]=false;
}tmp_c.clear();
if(dfs2(t)){
tmp=al;idx=0;
random_shuffle(all(tmp));
}
else{
idx++;
}
// out(t);
// outv(al);
done[t]=true;
}
// outv(tmp);
for(ll x:tmp)p[x]=tmp.size();
}
}
ll mi=n+1;
for(ll x:p)chmin(mi,x);
vector<int> ans(n);
rep(i,n)if(p[i]==mi)ans[i]=1;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:69:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | while(idx<tmp.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... |