// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define debug(x) cout<<#x<<" = "<<x<<endl
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const int INF = 1'000'000'007;
int a,b,m,edge_dirs[200005];
vii edges;
vi graph[2][400005];
bitset<400005> vis;
map<ii,int> edge_id;
vi order;
bool pass=0;
void dfs(int u) {
vis[u]=1;
trav(v,graph[pass][u]) if(!vis[v]) dfs(v);
if(!pass) order.pb(u);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cin>>a>>b>>m;
rep(i,0,m) {
int u,v;
cin>>u>>v;
edges.emplace_back(u-1,-(v-1));
edge_id[{u-1,v-1}]=i;
}
rep(i,0,a+b-1) {
if(i+1==a) continue;
graph[0][i].pb(i+1);
graph[1][i+1].pb(i);
}
sort(all(edges),greater<>());
int min_b=INF;
trav(edge,edges) {
int u,v;
tie(u,v)=edge;
v=-v;
bool dir=1;
if(v<min_b) {
min_b=v;
dir=0;
}
graph[dir][u].pb(v+a);
graph[!dir][v+a].pb(u);
edge_dirs[edge_id[{u,v}]]=dir;
}
int ans=0;
rep(i,0,a+b) if(!vis[i]) dfs(i);
vis.reset();
pass=1;
per(i,0,a+b) if(!vis[order[i]]) {
++ans;
dfs(order[i]);
}
cout<<ans<<endl;
rep(i,0,m) cout<<edge_dirs[i]<<' ';
cout<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
19292 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
19292 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
19292 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |