結果
問題 | No.1640 簡単な色塗り |
ユーザー |
![]() |
提出日時 | 2021-06-16 11:12:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,204 bytes |
コンパイル時間 | 1,415 ms |
コンパイル使用メモリ | 83,500 KB |
最終ジャッジ日時 | 2025-01-22 08:30:09 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 22 WA * 22 RE * 2 TLE * 7 |
ソースコード
//時間計測用 //構築未実装 #include <iostream> #include <stdio.h> #include <vector> #include <algorithm> #include <assert.h> #include <stdlib.h> #include <memory.h> #include <queue> #include <time.h> using namespace std; #define ll long long #define INF 1000000000000000000 ostream& operator<<(ostream& os,queue<ll> a){ while(!a.empty()){ ll t=a.front(); a.pop(); os<<t<<" "; } return os; } ll my_min(ll x,ll y){ if(x>y)return y; return x; } struct edge3{ ll to,cap,rev; }; ostream& operator<<(ostream& os,edge3& a){ return os<<a.to<<" "<<a.cap<<" "<<a.rev; } ostream& operator<<(ostream& os,vector<edge3>& a){ for(edge3 i:a){ os<<i<<"\n"; } return os; } //typedef struct Dinic{ //const ll INF=1000000000000000000; const ll MAX_V=200010; /* vector<edge3>* G; ll* level; ll* iter; */ vector<edge3> G[200010]; ll level[200010]; ll iter[200010]; //Dinic(){} /* Dinic(ll max_v){ MAX_V = max_v; G=new vector<edge3>[MAX_V]; level=new ll[MAX_V]; iter=new ll[MAX_V]; } */ void add_edge(ll from,ll to,ll cap){ G[from].push_back((edge3){to,cap,(ll)G[to].size()}); G[to].push_back((edge3){from,0,(ll)G[from].size()-1}); } void bfs(ll s){ memset(level,-1,sizeof(level)); queue<ll> que; level[s]=0; que.push(s); while(!que.empty()){ //cout<<que<<endl; ll v=que.front();que.pop(); //cout<<"v"<<v<<endl; //cout<<G[v]<<endl; for(ll i=0;i<(ll)G[v].size();i++){ edge3 &e=G[v][i]; if(e.cap>0 && level[e.to]<0){ level[e.to]=level[v]+1; que.push(e.to); } } } } ll dfs(ll v,ll t,ll f){ if(v==t)return f; //cout<<"&i:"<<iter[v]<<" "<<G[v].size()<<endl; for(ll &i=iter[v];i<(ll)G[v].size();i++){ edge3 &e=G[v][i]; //cout<<e.cap<<" "<<level[v]<<" "<<level[e.to]<<endl; if(e.cap>0 && level[v]<level[e.to]){ ll d=dfs(e.to,t,my_min(f,e.cap)); //cout<<"d:"<<d<<endl; if(d>0){ e.cap-=d; G[e.to][e.rev].cap+=d; return d; } } } return 0; } ll max_flow(ll s,ll t){ ll flow=0; for(;;){ bfs(s); //cout<<"bfs end\n"; if(level[t]<0)return flow; //cout<<level[t]<<endl; memset(iter,0,sizeof(iter)); ll f; while((f=dfs(s,t,INF))>0){ //cout<<f<<endl; flow+=f; } //cout<<f<<endl; } } //}; int main(){ time_t start=time(NULL); ll N,A,B; cin>>N; //Dinic F(200002); //Dinic F; //cout<<"INF:"<<F.INF<<endl; for(int i=0;i<N;i++){ //cerr<<i<<endl; cin>>A>>B; A--;B--; /* F.add_edge(200000,i,1); F.add_edge(i,100000+A,1); if(A!=B)F.add_edge(i,100000+B,1); F.add_edge(100000+i,200001,1); */ add_edge(200000,i,1); add_edge(i,100000+A,1); if(A!=B)add_edge(i,100000+B,1); add_edge(100000+i,200001,1); } //cerr<<"edge added\n"; //ll cnt=F.max_flow(200000,200001); ll cnt=max_flow(200000,200001); //cout<<cnt<<endl; if(cnt!=N){ cout<<"No\n"; return 0; } //ここから構築 cout<<"Yes\n"; cerr<<(double)time(NULL)-(double)start<<endl; return 0; }