Submission #756658

#TimeUsernameProblemLanguageResultExecution timeMemory
756658pccTeoretičar (COCI18_teoreticar)C++14
26 / 130
983 ms134600 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define fs first #define sc second struct Edge{ int id; int to; Edge(){ id = to = -1; } Edge(int ii,int tt){ id = ii; to = tt; } }; const int mxn = 2e5+10; bitset<mxn> done; vector<Edge> paths[mxn]; int deg[mxn],ans[mxn*3]; set<int> col[mxn]; int mex[mxn]; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int L,R,M; cin>>L>>R>>M; for(int i = 1;i<=M;i++){ int a,b; cin>>a>>b; paths[a].push_back(Edge(i,L+b)); paths[L+b].push_back(Edge(i,a)); deg[a]++; deg[L+b]++; } priority_queue<pair<int,int>,vector<pair<int,int>>,less<pair<int,int>>> pq; pair<int,int> s; vector<pair<int,int>> ord; for(int i = 1;i<=L+R;i++){ ord.push_back({deg[i],i}); pq.push({deg[i],i}); } int big = 0; for(int i = 1;i<=L+R;i++)big = max(big,(int)paths[i].size()); sort(ord.rbegin(),ord.rend()); fill(mex,mex+mxn,1); for(auto &kkk:ord){ if(done[kkk.sc])continue; /* cout<<endl; cout<<kkk.sc<<":"<<endl; */ pq.push(kkk); while(!pq.empty()){ auto now = pq.top(); //cout<<now.sc<<','; pq.pop(); if(done[now.sc])continue; done[now.sc] = true; while(col[now.sc].find(mex[now.sc]) != col[now.sc].end())mex[now.sc]++; for(auto nxt:paths[now.sc]){ if(ans[nxt.id])continue; int v = nxt.to; int u = now.sc; int tmp; for(tmp = mex[u];col[u].find(tmp) != col[u].end()||col[v].find(tmp) != col[v].end();tmp++); col[u].insert(tmp);col[v].insert(tmp); ans[nxt.id] = tmp; /* if(tmp>big){ cout<<endl; cout<<now.sc<<','<<nxt.to<<endl; exit(0); } */ while(col[now.sc].find(mex[now.sc]) != col[now.sc].end())mex[now.sc]++; /* deg[nxt.to]--; if(!done[nxt.to])pq.push({deg[nxt.to],nxt.to}); */ } } } int mx = *max_element(ans+1,ans+M+1); //cout<<mx<<' '<<big<<endl; assert(mx == big); cout<<mx<<'\n'; /* for(int i = 1;i<=M;i++){ if(!ans[i]){ for(int j = 0;j<1e9;j++)cout<<1; return 0; } } */ for(int i = 1;i<=M;i++)cout<<ans[i]<<'\n'; } /* 9 5 44 3 5 2 1 5 4 5 2 5 5 6 2 3 1 2 2 4 4 7 1 7 2 1 5 9 3 3 3 4 1 5 1 9 1 4 5 7 5 1 4 6 1 1 1 4 2 9 2 2 3 5 3 1 3 7 4 6 4 9 4 8 2 8 5 8 4 2 5 4 3 8 1 6 3 6 5 8 3 9 5 2 4 1 2 3 2 3 4 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...