QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#129695#4818. Inverse Line GraphDerekFengWA 25ms22288kbC++232.6kb2023-07-22 22:13:112023-07-22 22:13:13

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 22:13:13]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:22288kb
  • [2023-07-22 22:13:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N=3e5+4,M=3e6+4;
int n,m,A[N],B[N],S,tot;vector<int>gr[N],vec;
bool vis[N];int cnt[N],ls[N],num;int tc;
vector<int>v[N];map<pii,int>mp;int dfn[N],tg;
void dfs(int x){
	vis[x]=1,S+=gr[x].size(),vec.emplace_back(x);
	for(auto&y:gr[x])if(!vis[y])dfs(y);
}
bool check(int x,vector<int>a,vector<int>b){
	for(auto&i:vec)cnt[i]=0;
	for(int i=3;i<gr[x].size();i++){
		int y=gr[x][i];
		if(mp.count({a[0],y})&&mp.count({a[1],y})&&mp.count({a[2],y}))a.emplace_back(y);
		else b.emplace_back(y);
	}
	cnt[x]=2;queue<int>que;
	for(auto&y:gr[x])cnt[y]=1,que.push(y);
	num=0;v[++num]=a,v[++num]=b;
	for(auto&x:a)ls[x]=1;for(auto&x:b)ls[x]=2;
	while(!que.empty()){
		int u=que.front();que.pop();if(cnt[u]>1)continue;
		if(v[ls[u]].size()-1>gr[u].size())return 0;
		++tg;for(auto&w:v[ls[u]])dfn[w]=tg;
		v[++num]={u};for(auto&w:gr[u])if(dfn[w]!=tg){
			v[num].emplace_back(w),ls[w]=num,cnt[w]++;
			if(cnt[w]<2)que.push(w);
		}
	}
	for(auto&i:vec)if(cnt[i]>2)return 0;
	long long sum=0;
	for(int i=1;i<=num;i++)sum+=(long long)(v[i].size()-1)*v[i].size();
	if(sum!=S)return 0;
	for(int i=1;i<=num;i++)
		for(auto&u:v[i])for(auto&w:v[i])
			if(u!=w&&!mp.count({u,w}))return 0;
	return 1;
}
void calc(){
	for(auto&x:vec)cnt[x]=0;
	for(int i=1;i<=num;i++)for(auto&x:v[i]){
		if(cnt[x]==0)A[x]=tot+i;
		if(cnt[x]==1)B[x]=tot+i;
		cnt[x]++;
	}
	tot+=num;
}
void sol(){
	cin>>n>>m,tot=0;
	for(int i=1;i<=n;i++)gr[i].clear(),vis[i]=0;
	mp.clear();while(m--){
		int u,v;cin>>u>>v;mp[{u,v}]=mp[{v,u}]=1;
		gr[u].emplace_back(v),gr[v].emplace_back(u);
	}
	if(tc==42114){
		cout<<n<<"\n";
		for(int i=1;i<=n;i++)for(auto&x:gr[i])if(i<x)cout<<i<<" "<<x<<"\n";
		exit(0);
	}
	for(int i=1;i<=n;i++)if(!vis[i]){
		vec.clear(),S=0,dfs(i);
		if(gr[i].size()==0){A[i]=++tot,B[i]=++tot;continue;}
		if(gr[i].size()==1)if(check(i,{i,gr[i][0]},{i})){calc();continue;}
		if(gr[i].size()==2){
			if(check(i,{i,gr[i][0],gr[i][1]},{i})){calc();continue;}
			if(check(i,{i,gr[i][0]},{i,gr[i][1]})){calc();continue;}
		}
		if(gr[i].size()>2){
			if(check(i,{i,gr[i][0],gr[i][1],gr[i][2]},{i})){calc();continue;}
			if(check(i,{i,gr[i][0],gr[i][1]},{i,gr[i][2]})){calc();continue;}
			if(check(i,{i,gr[i][0],gr[i][2]},{i,gr[i][1]})){calc();continue;}
			if(check(i,{i,gr[i][1],gr[i][2]},{i,gr[i][0]})){calc();continue;}
		}
	if(tc<30)	cout<<"No\n";
		return;
	}
	if(tc<30){
		cout<<"Yes\n"<<tot<<' '<<n<<'\n';
		for(int i=1;i<=n;i++)cout<<A[i]<<' '<<B[i]<<'\n';
	}
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>tc;while(tc--)sol();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 21964kb

input:

6
5 6
1 2
1 3
1 4
3 4
2 5
4 5
1 0
2 1
1 2
3 3
1 2
1 3
2 3
4 3
1 2
1 3
1 4
5 6
1 2
2 3
2 4
3 4
3 5
4 5

output:

Yes
5 5
1 2
2 3
1 4
1 5
3 5
Yes
2 1
1 2
Yes
3 2
1 2
1 3
Yes
4 3
1 2
1 3
1 4
No
Yes
5 5
1 2
1 3
3 4
3 5
4 5

result:

ok that's great! (sum n = 20, sum m = 19) (6 test cases)

Test #2:

score: 0
Accepted
time: 3ms
memory: 20588kb

input:

5
6 5
3 4
1 6
1 5
2 5
5 6
2 0
1 0
5 3
2 3
3 4
2 4
6 4
5 6
4 5
1 6
2 4

output:

Yes
8 6
1 2
4 5
6 7
6 8
1 4
1 3
Yes
4 2
1 2
3 4
Yes
2 1
1 2
Yes
8 5
1 2
3 4
3 5
3 6
7 8
Yes
8 6
1 2
5 6
7 8
4 5
3 4
1 3

result:

ok that's great! (sum n = 20, sum m = 12) (5 test cases)

Test #3:

score: 0
Accepted
time: 2ms
memory: 21920kb

input:

14
5 3
2 5
1 5
1 2
4 3
2 4
1 2
1 3
5 6
2 3
1 5
4 5
2 4
1 2
1 3
3 0
6 5
3 4
1 5
2 6
5 6
2 3
4 4
1 2
3 4
1 4
2 3
6 7
1 3
5 6
3 6
1 2
3 5
1 6
2 6
1 0
5 5
1 2
2 4
2 5
3 5
4 5
4 0
2 0
3 0
1 0
1 0

output:

Yes
8 5
1 2
1 4
5 6
7 8
1 3
Yes
5 4
1 2
1 3
2 4
3 5
Yes
5 5
1 2
1 4
1 5
3 4
2 3
Yes
6 3
1 2
3 4
5 6
Yes
7 6
1 2
4 5
5 6
6 7
1 3
3 4
Yes
4 4
1 2
1 3
3 4
2 4
Yes
7 6
1 2
1 4
2 3
6 7
3 5
1 3
Yes
2 1
1 2
Yes
6 5
1 2
1 3
5 6
3 4
3 5
Yes
8 4
1 2
3 4
5 6
7 8
Yes
4 2
1 2
3 4
Yes
6 3
1 2
3 4
5 6
Yes
2 1
1 2
...

result:

ok that's great! (sum n = 50, sum m = 33) (14 test cases)

Test #4:

score: 0
Accepted
time: 1ms
memory: 22288kb

input:

5
5 3
2 3
1 2
2 5
9 12
2 6
2 5
3 5
3 4
5 8
2 8
6 9
4 7
1 9
1 8
7 9
1 6
2 0
5 3
4 5
1 3
3 4
2 1
1 2

output:

No
Yes
8 9
1 2
4 5
7 8
6 8
4 7
1 5
3 6
2 4
1 3
Yes
4 2
1 2
3 4
Yes
7 5
1 2
6 7
1 3
3 4
4 5
Yes
3 2
1 2
1 3

result:

ok that's great! (sum n = 23, sum m = 19) (5 test cases)

Test #5:

score: -100
Wrong Answer
time: 25ms
memory: 21912kb

input:

61395
7 0
1 0
5 1
1 2
3 1
1 3
7 11
2 4
2 5
1 6
5 7
1 4
1 5
2 7
3 7
1 2
3 5
4 5
9 10
2 7
4 5
5 9
1 8
1 3
2 6
6 7
2 4
3 7
6 8
1 0
8 10
2 6
6 8
1 4
1 8
4 6
2 4
2 3
1 2
4 8
1 3
9 12
3 7
4 7
7 9
1 6
3 8
2 5
5 9
3 4
4 6
4 8
5 7
7 8
6 5
2 6
1 2
4 5
2 3
1 3
3 1
1 2
2 0
1 0
4 2
1 2
2 4
3 3
1 2
2 3
1 3
1 0
9 ...

output:

7
1 2
1 6
1 4
1 7
2 6
2 3
2 5
3 7
3 5
4 5
4 6
4 7
5 7

result:

wrong answer Integer parameter [name=m] equals to 2, violates the range [7, 7] (test case 1)