[CF650C]Table Compression
Table Compression
题解
这不是离散化板题吗?WA穿了
看到这题应该很容易想到拓扑,根据每一行每一列的的相对大小关系建图,它的大小就是它的拓扑序。
然后,笔者又WA穿了。
我们还需要对同一行与同一列中值相等的点进行缩点,从而保证他们的值相同。
在缩完点后再建图跑一遍拓扑即可。
源码
#include<bits/stdc++.h>
using namespace std;
#define MAXN 1000005
typedef long long LL;
typedef unsigned long long uLL;
const LL INF=0x7f7f7f7f7f7f7f7f;
const int mo=1e9+7;
typedef pair<LL,LL> pii;
int n,m,tot,dis[MAXN],head[MAXN],idx;
int fa[MAXN],deg[MAXN],cnt;
vector<pii> col[MAXN],row[MAXN];
vector<int> vec;
queue<int> q;
struct ming{int w,id;}a[MAXN];
bool cmp(ming x,ming y){return x.w<y.w;}
struct edge{int to,nxt;}e[MAXN<<1];
void addEdge(int u,int v){e[++tot]=(edge){v,head[u]};head[u]=tot;}
int findSet(int x){return fa[x]==x?x:fa[x]=findSet(fa[x]);}
si

浙公网安备 33010602011771号