QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#559913#4892. 序列gan12340 0ms0kbC++111.6kb2024-09-12 10:29:132024-09-12 10:29:13

Judging History

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

  • [2024-09-12 10:29:13]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-09-12 10:29:13]
  • 提交

answer

#include<bits/stdc++.h>
#define MAXN 2000005
using namespace std;
int n,m;
int cnt;
vector<int>G[MAXN];
map<int,int>le[MAXN],ge[MAXN];
inline int id(int x,int v,int k){
	if(!k){
		int &res=le[x][v];
		if(!res)res=++cnt;
		return res;
	}else{
		int &res=ge[x][v];
		if(!res)res=++cnt;
		return res;
	}
}
inline int get(int i,int j,int k,int v){
	G[id(i,v+1,1)].push_back(id(j,v,0));G[id(i,v+1,1)].push_back(id(k,v,0));
	G[id(i,v-1,0)].push_back(id(j,v,1));G[id(i,v-1,0)].push_back(id(k,v,1));
}

int dfn[MAXN],low[MAXN],sccno[MAXN],scct,dfsc;
stack<int>S;
void dfs(int x){
	S.push(x);
	low[x]=dfn[x]=++dfsc;
	for(auto y:G[x]){
		if(!dfn[y]){
			dfs(y);
			low[x]=min(low[x],low[y]);
		}else if(!sccno)low[x]=min(low[x],dfn[y]);
	}
	if(low[x]==dfn[x]){
		scct++;
		while(1){
			int y=S.top();S.pop();
			sccno[y]=scct;
			if(x==y)break;
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	int x,y,z,v;
	for(int i=1;m>=i;i++){
		cin>>x>>y>>z>>v;
		get(x,y,z,v);get(y,x,z,v);get(z,x,y,v);		
	}
	for(int i=1;n>=i;i++){
		int lst=0;
		for(auto p:le[i]){
			if(lst&&p.second)G[lst].push_back(p.second);
			lst=p.second;
		}
		lst=0;
		for(auto p:ge[i]){
			if(lst&&p.second)G[p.second].push_back(lst);
			lst=p.second;
		}
	}
	for(int i=1;cnt>=i;i++)
		if(!dfn[i])dfs(i);
	for(int i=1;n>=i;i++)
		for(auto p:le[i]){
			if(sccno[p.second]==sccno[ge[i][p.first+1]]){
				puts("NO");
				return 0;
			}
		}
	puts("YES");
	for(int i=1;n>=i;i++){
		if(!le[i].size())cout<<"1 ";
		for(auto p:le[i]){
			if(sccno[p.second]<sccno[ge[i][p.first+1]]){
				cout<<p.first<<" ";
				break;
			}
		}
	}
	return 0;
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

10 10
6 3 10 133562624
8 7 6 685486592
4 2 7 332482851
10 8 9 211550017
2 10 1 165556251
10 8 5 211550017
6 8 2 332482851
4 9 2 332482851
8 1 4 193658790
9 6 10 728674154

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #9:

score: 0
Runtime Error

input:

40 9880
4 19 31 610502845
10 19 33 190412843
21 24 39 649028784
16 22 40 569593239
5 9 37 550862419
11 23 40 654613112
6 18 23 492267246
22 23 30 538715841
6 16 24 407919735
5 16 18 388907784
2 16 18 388907784
21 24 28 281403057
7 12 27 451830401
3 11 16 508407438
15 33 36 561955959
6 23 29 70605893...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%