結果
問題 | No.1745 Selfish Spies 2 (à la Princess' Perfectionism) |
ユーザー | smiken_61 |
提出日時 | 2021-11-18 01:32:49 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 1,234 ms / 5,000 ms |
コード長 | 10,153 bytes |
コンパイル時間 | 2,296 ms |
コンパイル使用メモリ | 194,348 KB |
実行使用メモリ | 87,732 KB |
最終ジャッジ日時 | 2024-06-06 18:33:52 |
合計ジャッジ時間 | 17,762 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
8,064 KB |
testcase_01 | AC | 4 ms
8,064 KB |
testcase_02 | AC | 3 ms
8,064 KB |
testcase_03 | AC | 4 ms
8,064 KB |
testcase_04 | AC | 4 ms
8,064 KB |
testcase_05 | AC | 4 ms
8,064 KB |
testcase_06 | AC | 5 ms
8,064 KB |
testcase_07 | AC | 4 ms
8,064 KB |
testcase_08 | AC | 4 ms
8,064 KB |
testcase_09 | AC | 5 ms
8,192 KB |
testcase_10 | AC | 4 ms
8,064 KB |
testcase_11 | AC | 5 ms
8,064 KB |
testcase_12 | AC | 5 ms
8,192 KB |
testcase_13 | AC | 6 ms
8,192 KB |
testcase_14 | AC | 6 ms
8,320 KB |
testcase_15 | AC | 6 ms
8,320 KB |
testcase_16 | AC | 7 ms
8,320 KB |
testcase_17 | AC | 10 ms
8,832 KB |
testcase_18 | AC | 10 ms
8,832 KB |
testcase_19 | AC | 4 ms
8,064 KB |
testcase_20 | AC | 4 ms
8,192 KB |
testcase_21 | AC | 6 ms
8,064 KB |
testcase_22 | AC | 5 ms
8,192 KB |
testcase_23 | AC | 5 ms
8,192 KB |
testcase_24 | AC | 40 ms
11,028 KB |
testcase_25 | AC | 8 ms
8,576 KB |
testcase_26 | AC | 8 ms
8,576 KB |
testcase_27 | AC | 16 ms
9,088 KB |
testcase_28 | AC | 184 ms
22,944 KB |
testcase_29 | AC | 15 ms
9,216 KB |
testcase_30 | AC | 15 ms
9,088 KB |
testcase_31 | AC | 15 ms
9,088 KB |
testcase_32 | AC | 15 ms
9,088 KB |
testcase_33 | AC | 182 ms
23,072 KB |
testcase_34 | AC | 175 ms
22,856 KB |
testcase_35 | AC | 188 ms
22,808 KB |
testcase_36 | AC | 191 ms
23,064 KB |
testcase_37 | AC | 192 ms
23,060 KB |
testcase_38 | AC | 178 ms
22,820 KB |
testcase_39 | AC | 62 ms
13,372 KB |
testcase_40 | AC | 109 ms
18,120 KB |
testcase_41 | AC | 106 ms
17,752 KB |
testcase_42 | AC | 228 ms
28,224 KB |
testcase_43 | AC | 335 ms
36,672 KB |
testcase_44 | AC | 464 ms
45,640 KB |
testcase_45 | AC | 1,005 ms
62,636 KB |
testcase_46 | AC | 1,042 ms
62,624 KB |
testcase_47 | AC | 1,199 ms
86,248 KB |
testcase_48 | AC | 1,234 ms
86,496 KB |
testcase_49 | AC | 552 ms
39,064 KB |
testcase_50 | AC | 519 ms
38,792 KB |
testcase_51 | AC | 147 ms
17,756 KB |
testcase_52 | AC | 128 ms
22,332 KB |
testcase_53 | AC | 152 ms
22,060 KB |
testcase_54 | AC | 503 ms
45,536 KB |
testcase_55 | AC | 469 ms
44,748 KB |
testcase_56 | AC | 908 ms
47,612 KB |
testcase_57 | AC | 1,029 ms
87,720 KB |
testcase_58 | AC | 1,101 ms
87,732 KB |
ソースコード
#include <bits/stdc++.h> // #include <atcoder/all> //using namespace atcoder; // tabaicho see https://boostjp.github.io/tips/multiprec-int.html //#include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; // cpp_int // int128_t // int256_t // int512_t // int1024_t // uint128_t // uint256_t // uint512_t // uint1024_t #define int long long #define inf 1000000007 // #define inf 998244353 #define pa pair<int,int> #define ppa pair<pa,pa> #define ll long long #define PI 3.14159265358979323846 #define mp make_pair #define pb push_back #define EPS (1e-8) using namespace std; int dx[8]={0,1,0,-1,1,1,-1,-1}; int dy[8]={1,0,-1,0,-1,1,1,-1}; class pa3{ public: int x; int y,z; pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {} bool operator < (const pa3 &p) const{ if(x!=p.x) return x<p.x; if(y!=p.y) return y<p.y; return z<p.z; //return x != p.x ? x<p.x: y<p.y; } bool operator > (const pa3 &p) const{ if(x!=p.x) return x>p.x; if(y!=p.y) return y>p.y; return z>p.z; //return x != p.x ? x<p.x: y<p.y; } bool operator == (const pa3 &p) const{ return x==p.x && y==p.y && z==p.z; } bool operator != (const pa3 &p) const{ return !( x==p.x && y==p.y && z==p.z); } }; class pa4{ public: int x; int y,z,w; pa4(int x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {} bool operator < (const pa4 &p) const{ if(x!=p.x) return x<p.x; if(y!=p.y) return y<p.y; if(z!=p.z)return z<p.z; return w<p.w; //return x != p.x ? x<p.x: y<p.y; } bool operator > (const pa4 &p) const{ if(x!=p.x) return x>p.x; if(y!=p.y) return y>p.y; if(z!=p.z)return z>p.z; return w>p.w; //return x != p.x ? x<p.x: y<p.y; } bool operator == (const pa4 &p) const{ return x==p.x && y==p.y && z==p.z &&w==p.w; } }; class pa2{ public: int x,y; pa2(int x=0,int y=0):x(x),y(y) {} pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);} pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);} bool operator < (const pa2 &p) const{ return y != p.y ? y<p.y: x<p.x; } bool operator > (const pa2 &p) const{ return x != p.x ? x<p.x: y<p.y; } bool operator == (const pa2 &p) const{ return abs(x-p.x)==0 && abs(y-p.y)==0; } bool operator != (const pa2 &p) const{ return !(abs(x-p.x)==0 && abs(y-p.y)==0); } }; string itos( int i ) { ostringstream s ; s << i ; return s.str() ; } int Gcd(int v,int b){ if(v==0) return b; if(b==0) return v; if(v>b) return Gcd(b,v); if(v==b) return b; if(b%v==0) return v; return Gcd(v,b%v); } int extgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } int d = extgcd(b, a%b, y, x); y -= a/b * x; return d; } pa operator+(const pa & l,const pa & r) { return {l.first+r.first,l.second+r.second}; } pa operator-(const pa & l,const pa & r) { return {l.first-r.first,l.second-r.second}; } ostream& operator<<(ostream& os, const vector<int>& VEC){ for(auto v:VEC)os<<v<<" "; return os; } ostream& operator<<(ostream& os, const pa& PAI){ os<<PAI.first<<" : "<<PAI.second; return os; } ostream& operator<<(ostream& os, const pa3& PAI){ os<<PAI.x<<" : "<<PAI.y<<" : "<<PAI.z; return os; } ostream& operator<<(ostream& os, const pa4& PAI){ os<<PAI.x<<" : "<<PAI.y<<" : "<<PAI.z<<" : "<<PAI.w; return os; } ostream& operator<<(ostream& os, const vector<pa>& VEC){ for(auto v:VEC)os<<v<<" "; return os; } ostream& operator<<(ostream& os, const vector<pa3>& VEC){ for(auto v:VEC){ os<<v<<" "; os<<endl; } return os; } int beki(int wa,ll rr,int warukazu){ if(rr==0) return 1%warukazu; if(rr==1) return wa%warukazu; wa%=warukazu; if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu; ll zx=beki(wa,rr/2,warukazu); return (zx*zx)%warukazu; } int pr[2521000]; int inv[2521000]; const int mod=998244353; int comb(int nn,int rr){ if(nn==-1&&rr==-1)return 1; if(rr<0 || rr>nn || nn<0) return 0; int r=pr[nn]*inv[rr]; r%=mod; r*=inv[nn-rr]; r%=mod; return r; } void gya(int ert){ pr[0]=1; for(int i=1;i<=ert;i++){ pr[i]=((ll)pr[i-1]*i)%mod; } inv[ert]=beki(pr[ert],mod-2,mod); for(int i=ert-1;i>=0;i--){ inv[i]=(ll)inv[i+1]*(i+1)%mod; } } // cin.tie(0); // ios::sync_with_stdio(false); //priority_queue<pa3,vector<pa3>,greater<pa3>> pq; //sort(ve.begin(),ve.end(),greater<int>()); // mt19937(clock_per_sec); // mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ; struct DM_decomposition{ private: public: int V; const int MAX=1000000000; // < N vector<vector<int>> gr[2]; vector<int>mm_use,group,vis; vector<int>ssc_jun; /* void dfs_nibu(int r,int d){ if(nibu[r]>=0)return; nibu[r]=d; for(auto v:gr[0][r])dfs_nibu(v,1-d); } */ void dfs_toutatu(int r,int muki,int d){ if(group[r]>=0){ assert(group[r]==d); return; } //cout<<r<<" "<<d<<endl; group[r]=d; for(auto v:gr[muki][r])dfs_toutatu(v,muki,d); } void dfs_ssc(int r){ if(vis[r])return; vis[r]=1; for(auto v:gr[0][r])if(group[v]!=0 && group[v]!=MAX)dfs_ssc(v); ssc_jun.pb(r); } void dfs_ssc2(int r,int d){ if(vis[r]==2)return; group[r]=d; vis[r]=2; for(auto v:gr[1][r])if(group[v]!=0 && group[v]!=MAX)dfs_ssc2(v,d); } vector<pair<vector<int>,vector<int>>> shori(int N,vector<int>nibu,vector<pa>eda,vector<pa>MM){ V=N; gr[0].resize(N,{}); gr[1].resize(N,{}); mm_use.resize(N,0); group.resize(N,-1); vis.resize(N,0); /* for(auto v:eda){ gr[0][v.first].pb(v.second); gr[0][v.second].pb(v.first); } for(int i=0;i<V;i++)dfs_nibu(i,0); gr[0].clear(); gr[0].resize(N,{}); */ for(auto v:eda){ if(nibu[v.first]==1)swap(v.second,v.first); assert(nibu[v.first]==0); assert(nibu[v.second]==1); gr[0][v.first].pb(v.second); gr[1][v.second].pb(v.first); } for(auto v:MM){ if(nibu[v.first]==1)swap(v.second,v.first); assert(nibu[v.first]==0); assert(nibu[v.second]==1); gr[0][v.second].pb(v.first); gr[1][v.first].pb(v.second); mm_use[v.first]=1; mm_use[v.second]=1; } for(int i=0;i<V;i++)if(!mm_use[i]){ if(nibu[i])dfs_toutatu(i,1,0); else dfs_toutatu(i,0,MAX); } for(int i=0;i<V;i++)if(group[i]!=0 && group[i]!=MAX)dfs_ssc(i); // cout<<ssc_jun<<endl; reverse(ssc_jun.begin(),ssc_jun.end()); int cnt=1; for(auto v:ssc_jun){ if(vis[v]==1){ dfs_ssc2(v,cnt); cnt++; } } for(auto &v:group)if(v==MAX)v=cnt; // cout<<group<<endl; vector<pair<vector<int>,vector<int>>>ans(cnt+1); for(int i=0;i<V;i++){ if(nibu[i]==0)ans[group[i]].first.pb(i); else ans[group[i]].second.pb(i); } return ans; } }; struct edge{ int to,cap,num,moto; }; vector<edge> ZANYO[200020]; int label[200020]; queue<pa> qu_bfs; int dokomade[200020]; void add_edge(int s_point,int t_point, int capa){// (s!=t) s-->t ZANYO[s_point].pb((edge){t_point,capa,(int)ZANYO[t_point].size(),0}); ZANYO[t_point].pb((edge){s_point,0,(int)ZANYO[s_point].size()-1,1}); } void bfs_dinic(int s_point,int N){ for(int i=0;i<N;i++)label[i]=-1; while(qu_bfs.size())qu_bfs.pop(); qu_bfs.push(mp(s_point,0)); while(qu_bfs.size()){ pa z=qu_bfs.front(); qu_bfs.pop(); if(label[z.first]>=0)continue; label[z.first]=z.second; for(auto &v:ZANYO[z.first]){ if(v.cap==0) continue; if(v.cap<0){ cout<<"error"<<endl; exit(0); } if(label[v.to]>=0) continue; qu_bfs.push(mp(v.to,z.second+1)); } } return; } int dfs_dinic(int s_point,int t_point, int ima_flow){ if(s_point==t_point) return ima_flow; while(1){ if(dokomade[s_point]>=(int)ZANYO[s_point].size()) break; int edanum=dokomade[s_point]; if(ZANYO[s_point][edanum].cap<0){ cout<<"minus"<<endl; exit(0); } if(ZANYO[s_point][edanum].cap<=0 || label[s_point]+1!=label[ZANYO[s_point][edanum].to] ){ dokomade[s_point]++; continue; } int W=dfs_dinic(ZANYO[s_point][edanum].to,t_point,min(ZANYO[s_point][edanum].cap,ima_flow)); if(W>0){ ZANYO[s_point][edanum].cap-=W; ZANYO[ZANYO[s_point][edanum].to][ZANYO[s_point][edanum].num].cap+=W; return W; } dokomade[s_point]++; } return 0; } int max_flow_dinic(int s_point,int t_point,int N){// Nは頂点数:存在する頂点番号が[0,N) (Nは多めにしてOK) int jougen=inf*1000000000ll; //容量の最大値 int ans_flow=0; while(1){ bfs_dinic(s_point,N); if(label[t_point]==-1) break; for(int i=0;i<N;i++)dokomade[i]=0; while(1){ int ima_flow=dfs_dinic(s_point,t_point,jougen+1); if(ima_flow==0)break; ans_flow+=ima_flow; } } return ans_flow; } void solve(){ int n,m,l; cin>>n>>m>>l; vector<pa>eda; for(int i=0;i<l;i++){ int y,yy; cin>>y>>yy; y--,yy--; eda.pb(mp(y,n+yy)); add_edge(y,n+yy,1); } for(int i=0;i<n;i++)add_edge(n+m,i,1); for(int i=n;i<n+m;i++)add_edge(i,n+m+1,1); max_flow_dinic(n+m,n+m+1,n+m+4); //cout<<eda<<endl; //bi_match bi(n+m); //for(auto v:eda)bi.add_edge(v.first,v.second); //cout<<(int)eda.size()-bi.solve()<<endl; //bi.solve(); vector<pa>mm; for(int i=0;i<n;i++)for(auto v:ZANYO[i])if(v.to!=n+m)if(v.cap==0)mm.pb(mp(i,v.to)); //for(int i=0;i<n;i++)if(bi.match[i]>=0)mm.pb(mp(i,bi.match[i])); //cout<<mm<<endl; vector<int>tmp(n+m,0); for(int i=n;i<n+m;i++)tmp[i]=1; DM_decomposition ss; auto V=ss.shori(n+m,tmp,eda,mm); int G=(int)V.size()-1; vector<int>iro(n+m,-1); for(int i=0;i<=G;i++){ for(auto w:V[i].first)iro[w]=i; for(auto w:V[i].second)iro[w]=i; } for(auto v:eda){ int p=iro[v.first]; int q=iro[v.second]; if(p!=q)cout<<"No"<<endl; else cout<<"Yes"<<endl; //else if(1<=p&&p<G&&(int)V[p].first.size()==1)cout<<-1<<endl; //else cout<<0<<endl; } } signed main(){ //mod=inf; cin.tie(0); ios::sync_with_stdio(false); int n=1; //cin>>n; for(int i=0;i<n;i++)solve(); return 0; }