还是很裸的精确覆盖,没什么好说的了
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<cctype>
#include<string>
#include<algorithm>
#include<iostream>
#include<ctime>
#include<map>
#include<set>
using namespace std;
#define MP(x,y) make_pair((x),(y))
#define PB(x) push_back(x)
typedef __int64 LL;
//typedef unsigned __int64 ULL;
/* ****************** */
const int INF=100011122;
const double INFF=1e100;
const double eps=1e-8;
const LL mod=9999991;
const int NN=10000010;
const int MM=2000010;
/* ****************** */
const int maxnode = 370000+375;
const int maxn = 370;
const int maxr = 1005;
int ansd,ans[maxn];
int sz,H[maxr],S[maxn];
int row[maxnode],col[maxnode];
int U[maxnode],D[maxnode],L[maxnode],R[maxnode];
bool mat[65][65];
int re[maxr][3],maxx[maxr][2];
void dl_init(int n)
{
memset(H,-1,sizeof(H));
int i;
for(i=0;i<=n;i++)
{
U[i]=D[i]=i;
L[i]=i-1;
R[i]=i+1;
S[i]=0;
}
L[0]=n;
R[n]=0;
sz=n+1;
}
void dl_add(int r,int c)
{
row[sz]=r,col[sz]=c;
S[c]++;
U[sz]=U[c];
D[sz]=c;
D[U[c]]=sz;
U[c]=sz;
if(H[r]==-1)H[r]=L[sz]=R[sz]=sz;
else
{
L[sz]=L[H[r]];
R[sz]=H[r];
R[ L[sz] ]=sz;
L[ H[r] ]=sz;
}
sz++;
}
void remove(int c)
{
L[R[c]]=L[c];
R[L[c]]=R[c];
int i,j;
for(i=D[c];i!=c;i=D[i])
for(j=R[i];j!=i;j=R[j])
{
U[D[j]]=U[j];
D[U[j]]=D[j];
S[ col[j] ]--;
}
}
void restore(int c)
{
int i,j;
for(i=U[c];i!=c;i=U[i])
for(j=L[i];j!=i;j=L[j])
{
U[D[j]]=j;
D[U[j]]=j;
S[ col[j] ]++;
}
L[R[c]]=c;
R[L[c]]=c;
}
bool dl_dfs(int d)
{
if(R[0]==0)
{
ansd=d;
return true;
}
int i,j,c=R[0];
bool fg=false;
for(i=R[0];i!=0;i=R[i])
if(S[i]<S[c])
c=i;
remove(c);
for(i=D[c];i!=c;i=D[i])
{
ans[d]=row[i];
for(j=R[i];j!=i;j=R[j])remove(col[j]);
fg=dl_dfs(d+1);
for(j=L[i];j!=i;j=L[j])restore(col[j]);
if(fg)break;
}
restore(c);
return fg;
}
int main()
{
int n,m,d,i,j,k,jj,kk;
int u,v,si,ei,tol;
while(scanf("%d%d%d",&n,&m,&d)!=EOF)
{
dl_init(n*d+n);
memset(mat,false,sizeof(mat));
while(m--)
{
scanf("%d%d",&u,&v);
mat[u][v]=mat[v][u]=true;
}
tol=0;
for(i=1;i<=n;i++)
{
scanf("%d%d",&si,&ei);
dl_add(++tol,i);
re[tol][0]=i;
re[tol][1]=0;
re[tol][2]=0;
for(j=si;j<=ei;j++)
for(k=j;k<=ei;k++)
{
tol++;
dl_add(tol,i);
re[tol][0]=i;
re[tol][1]=j;
re[tol][2]=k;
for(jj=j;jj<=k;jj++)
for(kk=1;kk<=n;kk++)
if(mat[i][kk] || i==kk)
{
dl_add(tol,jj*n+kk);
}
}
}
ansd=-1;
// puts("go to dfs");
dl_dfs(0);
// puts("end of dfs");
if(ansd==-1)
puts("No solution");
else
{
if(ansd!=n)
while(1);
for(i=0;i<ansd;i++)
{
j=ans[i];
maxx[ re[j][0] ][0]=re[j][1];
maxx[ re[j][0] ][1]=re[j][2];
}
for(i=1;i<=n;i++)
{
printf("%d %d\n",maxx[i][0],maxx[i][1]);
}
}
puts("");
}
return 0;
}