QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#49169 | #1812. Interesting Coloring | Crysfly | WA | 7ms | 16668kb | C++11 | 2.4kb | 2022-09-19 16:05:52 | 2022-09-19 16:05:54 |
Judging History
answer
// what is matter? never mind.
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
//#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 500005
#define inf 0x3f3f3f3f
int n,m;
struct edge{
int to,nxt,w;
}e[maxn];
int tot=1,head[maxn];
vi out[maxn];
void adde(int u,int v){
e[++tot]=(edge){v,head[u]};
head[u]=tot;
}
int col[maxn];
int sz[maxn],fa[maxn],up[maxn],dep[maxn];
void dfs(int u)
{
sz[u]=1;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if((i^1)==up[u])continue;
if(!dep[v]){
// cout<<"dfs "<<u<<" "<<v<<" "<<(i/2)<<endl;
dep[v]=dep[u]+1,fa[v]=u,up[v]=i;
dfs(v),sz[u]+=sz[v];
}
}
}
int cnt;
int rnk[maxn],cnte[maxn];
bool in[maxn]; vi o;
void make(int u,int v){
while(u!=v){
++cnte[col[up[u]]];
if(!in[col[up[u]]])in[col[up[u]]]=1,o.pb(col[up[u]]);
u=fa[u];
}
}
void clr(){
for(int x:o)in[x]=cnte[x]=0;
o.clear();
}
bool cmp(pii x,pii y){
return sz[x.fi]>sz[y.fi];
}
void solve(int u)
{
vector<pii>son;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if((i^1)==up[u])continue;
if(dep[v]<dep[u]){
make(u,v);
col[i]=col[i^1]=++cnt;
out[i>>1]=o;
for(int x=u;x!=v;x=fa[x]){
int j=up[x];
if(!out[j>>1].size()){
out[j>>1].pb(cnt);
--cnte[col[j]];
for(int _:o)if(cnte[_])out[j>>1].pb(_);
++cnte[col[j]];
}
}
clr();
}
else if(up[v]==i)son.pb(mkp(v,i));
}
sort(son.begin(),son.end(),cmp);
if(fa[u])make(fa[u],1);
while(o.size()<son.size())o.pb(++cnt);
// cout<<"u: "<<u<<endl;
// cout<<"son: "<<son.size()<<endl;
// for(auto t:o)cout<<t<<" ";puts("");
int p=0;
for(auto t:son){
int v=t.fi,i=t.se;
col[i]=col[i^1]=o[p++];
}
clr();
for(auto t:son)solve(t.fi);
}
signed main()
{
n=read(),m=read();
For(i,1,m){
int u=read(),v=read();
adde(u,v),adde(v,u);
}
dep[1]=1,dfs(1);
solve(1);
For(i,1,m)cout<<col[i<<1]<<" \n"[i==m];
For(i,1,m){
cout<<out[i].size()<<" ";
for(auto t:out[i])cout<<t<<" \n"[t==out[i].back()];
}
return 0;
}
// e1e1e2 d7d7d8 f7f7f7
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 16668kb
input:
10 11 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 1 10 1 4
output:
5 1 3 2 1 2 1 2 1 4 1 2 1 3 3 5 1 3 2 5 1 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 2 1 2 3 4 1 2
result:
ok accepted
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 16404kb
input:
10 15 3 6 2 10 3 7 6 8 1 6 2 6 4 5 6 10 4 9 5 9 4 8 5 6 6 7 4 6 1 10
output:
9 10 2 8 3 5 7 2 2 1 1 6 4 1 1 2 2 4 2 5 2 2 9 4 1 1 2 2 1 2 10 2 2 1 2 2 3 1 2 6 1 3 6 1 2 2 8 1 2 1 2 2 9 2 3 6 1 2 2 3 2
result:
wrong answer wrong answer, vertex 4 is shared by two same-color edges