Submission #44669216
Source Code Expand
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const int MAXN = 4e5+10,MAXM = 4e5+10,INF = 1e9;
int T,n,d;
int a[MAXM],b[MAXM],x[MAXM],y[MAXM];
int s,t;
int dis[MAXN],cur[MAXN];
queue<int>q;
vector<int>g[MAXN];
struct E{
int u,v,c,f;
}e[MAXM];
int fst[MAXN],nxt[MAXM],tot;
void Init(){
rep(i,1,tot)nxt[i] = 0;
rep(i,1,t)fst[i] = 0;
tot = 0;
}
void adde(int u,int v,int c){
e[++tot] = (E){u,v,c,0};
nxt[tot] = fst[u];fst[u] = tot;
}
void link(int u,int v,int c){
adde(u,v,c);adde(v,u,0);
}
int bfs(){
fill(dis+1,dis+1+t,INF);
dis[s] = 0;q.push(s);
while(q.size()){
int u = q.front();q.pop();
for(int j=fst[u];j;j=nxt[j])if(e[j].c-e[j].f){
int v = e[j].v;
if(dis[v] > dis[u]+1){
dis[v] = dis[u]+1;
q.push(v);
}
}
}
return dis[t] != INF;
}
int dfs(int u,int f){
if(u==t || !f)return f;
int ret = 0;
for(int& j=cur[u];j;j=nxt[j]){
int v = e[j].v;
if(dis[v] != dis[u]+1)continue;
int val = dfs(v,min(f,e[j].c-e[j].f));
ret += val,f -= val;
e[j].f += val,e[op(j)].f -= val;
if(!f)break;
}
return ret;
}
int dinic(){
int ret = 0;
while(bfs()){
rep(i,1,t)cur[i] = fst[i];
ret += dfs(s,INF);
}
return ret;
}
void tomin(int& x,int y){x=min(x,y);}
int dfn[MAXN],low[MAXN],ins[MAXN],st[MAXN],top,dtot,num;
void tj(int u){
dfn[u] = low[u] = ++dtot;
ins[u] = 1;st[++top] = u;
for(auto v:g[u]){
if(!dfn[v])tj(v),tomin(low[u],low[v]);
else if(ins[v])tomin(low[u],low[v]);
}
if(low[u] >= dfn[u]){
num++;
while(1){
int nd = st[top--];
ins[nd] = 0;
if(nd==u)break;
}
}
}
int tj(){
rep(i,1,n)dfn[i] = ins[i] = 0;
top = dtot = num = 0;
rep(i,1,n)if(!dfn[i])tj(i);
return num;
}
//
void solve(){
cin>>n>>d;
rep(i,1,n)g[i].clear();
rep(i,1,n*d){
cin>>a[i]>>b[i];
}
Init();
s = n*d+n+1,t = s+1;
rep(i,1,n*d){
link(s,i,1);
x[i] = tot+1;
link(i,n*d+a[i],INF);
y[i] = tot+1;
link(i,n*d+b[i],INF);
}
rep(i,1,n){
link(n*d+i,t,d);
}
int ret = dinic();
assert(ret <= n*d);
if(ret != n*d){
cout<<"No\n";
return;
}
rep(i,1,n*d){
if(e[x[i]].f == 1){
g[a[i]].push_back(b[i]);
}else{
g[b[i]].push_back(a[i]);
}
}
rep(i,1,n)assert(g[i].size() == d);
//
if(tj() > 1){
cout<<"No\n";
}else{
cout<<"Yes\n";
}
}
int main(){
cin>>T;
while(T--)solve();
return 0;
}
Submission Info
Compile Error
In file included from /usr/include/c++/9/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
from ./Main.cpp:1:
./Main.cpp: In function ‘void solve()’:
./Main.cpp:159:31: warning: comparison of integer expressions of different signedness: ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
159 | rep(i,1,n)assert(g[i].size() == d);
| ~~~~~~~~~~~~^~~~
Judge Result
| Set Name |
Sample |
All |
after_contest |
| Score / Max Score |
0 / 0 |
900 / 900 |
0 / 0 |
| Status |
|
|
|
| Set Name |
Test Cases |
| Sample |
00-sample-001.txt |
| All |
00-sample-001.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt, 01-041.txt, 01-042.txt |
| after_contest |
after_contest_001.txt, after_contest_002.txt, after_contest_003.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00-sample-001.txt |
AC |
18 ms |
13060 KB |
| 01-001.txt |
AC |
35 ms |
12988 KB |
| 01-002.txt |
AC |
35 ms |
13056 KB |
| 01-003.txt |
AC |
39 ms |
13652 KB |
| 01-004.txt |
AC |
38 ms |
13720 KB |
| 01-005.txt |
AC |
52 ms |
13340 KB |
| 01-006.txt |
AC |
57 ms |
13656 KB |
| 01-007.txt |
AC |
60 ms |
16660 KB |
| 01-008.txt |
AC |
59 ms |
16576 KB |
| 01-009.txt |
AC |
50 ms |
13328 KB |
| 01-010.txt |
AC |
39 ms |
13700 KB |
| 01-011.txt |
AC |
45 ms |
16720 KB |
| 01-012.txt |
AC |
42 ms |
16712 KB |
| 01-013.txt |
AC |
50 ms |
29000 KB |
| 01-014.txt |
AC |
121 ms |
23912 KB |
| 01-015.txt |
AC |
79 ms |
22088 KB |
| 01-016.txt |
AC |
61 ms |
21312 KB |
| 01-017.txt |
AC |
41 ms |
17176 KB |
| 01-018.txt |
AC |
42 ms |
17084 KB |
| 01-019.txt |
AC |
38 ms |
16864 KB |
| 01-020.txt |
AC |
38 ms |
16868 KB |
| 01-021.txt |
AC |
38 ms |
15056 KB |
| 01-022.txt |
AC |
42 ms |
20496 KB |
| 01-023.txt |
AC |
39 ms |
20476 KB |
| 01-024.txt |
AC |
32 ms |
16016 KB |
| 01-025.txt |
AC |
37 ms |
16092 KB |
| 01-026.txt |
AC |
40 ms |
14304 KB |
| 01-027.txt |
AC |
29 ms |
13148 KB |
| 01-028.txt |
AC |
20 ms |
13088 KB |
| 01-029.txt |
AC |
33 ms |
13080 KB |
| 01-030.txt |
AC |
56 ms |
29088 KB |
| 01-031.txt |
AC |
63 ms |
29044 KB |
| 01-032.txt |
AC |
86 ms |
26896 KB |
| 01-033.txt |
AC |
119 ms |
23928 KB |
| 01-034.txt |
AC |
126 ms |
23916 KB |
| 01-035.txt |
AC |
170 ms |
23360 KB |
| 01-036.txt |
AC |
74 ms |
22152 KB |
| 01-037.txt |
AC |
80 ms |
22012 KB |
| 01-038.txt |
AC |
93 ms |
21960 KB |
| 01-039.txt |
AC |
45 ms |
14648 KB |
| 01-040.txt |
AC |
41 ms |
13020 KB |
| 01-041.txt |
AC |
56 ms |
24940 KB |
| 01-042.txt |
AC |
53 ms |
24836 KB |
| after_contest_001.txt |
AC |
49 ms |
13668 KB |
| after_contest_002.txt |
AC |
80 ms |
21656 KB |
| after_contest_003.txt |
AC |
80 ms |
21712 KB |