QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#734741#4892. 序列NineSuns0 17ms45660kbC++142.4kb2024-11-11 14:44:542024-11-11 14:44:55

Judging History

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

  • [2024-11-11 14:44:55]
  • 评测
  • 测评结果:0
  • 用时:17ms
  • 内存:45660kb
  • [2024-11-11 14:44:54]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back

using namespace std;
const int N = 2e5+5; 
int n, m, a[N], b[N], c[N], d[N], p[4], dfn[N*4], low[N*4], sid[N*4], sc, dt, stk[N*4], ed, istk[N*4], mk[N*4]; 
vector <int> v[N], e[N*4]; 
map <int, int> id[N]; 

void tarjan (int p) {
	dfn[p] = low[p] = ++dt; 
	istk[p] = 1; stk[++ed] = p; 
	for (int i : e[p]) {
		if (!dfn[i]) {
			tarjan(i); low[p] = min(low[p], low[i]); 
		}
		else if (istk[i]) low[p] = min(low[p], dfn[i]); 
	}
	if (dfn[p] == low[p]) {
		int x; ++sc; 
		do {
			x = stk[ed--]; istk[x] = 0; 
			sid[x] = sc; 
		} while (x^p);
	}
}

int main () {
	cin >> n >> m; 
	for (int i = 1;i <= m;i++) {
		int x, y, z, k; 
		cin >> x >> y >> z >> k; 
		a[i] = x; b[i] = y; c[i] = z; d[i] = k; 
		v[x].pb(k); v[y].pb(k); v[z].pb(k); 
	}
	int S = 0; 
	for (int i = 1;i <= n;i++) v[i].pb(0), v[i].pb(1e9+1); 
	for (int i = 1;i <= n;i++) {
		sort(v[i].begin(), v[i].end()); 
		v[i].resize(unique(v[i].begin(), v[i].end())-v[i].begin()); 
		for (int j : v[i]) id[i][j] = ++S; //, cout << i << " " << j << " " << S << endl; 
	} 
//	cout << endl; 
	for (int i = 1;i <= n;i++) {
		for (int j : v[i]) {
			if (j <= 1e9) e[id[i][j]].pb(id[i][j]+1); 
		}
		for (int j : v[i]) {
			if (j > 0) e[id[i][j]+S].pb(id[i][j]+S-1); 
		}
	}
	for (int i = 1;i <= m;i++) {
		p[0] = a[i]; p[1] = b[i]; p[2] = c[i]; 
		sort(p, p+3); 
		do {
			e[id[p[0]][d[i]]-1].pb(id[p[1]][d[i]]+S); 
//			e[id[p[0]][d[i]]-1].pb(id[p[2]][d[i]]+S); 	
			e[id[p[0]][d[i]]+1+S].pb(id[p[1]][d[i]]); 
//			e[id[p[0]][d[i]]+1+S].pb(id[p[2]][d[i]]); 
//			cout << id[p[0]][d[i]]-1 << " " << id[p[1]][d[i]]+S << endl; 
//			cout << id[p[0]][d[i]]+1+S << " " << id[p[1]][d[i]] << endl; 
		} while (next_permutation(p, p+3)); 
	}
	for (int i = 1;i <= S+S;i++) if (!dfn[i]) tarjan(i); 
	for (int i = 1;i <= n;i++) {
		for (int j : v[i]) {
			if (j <= 1e9) {
				if (sid[id[i][j]] == sid[id[i][j]+1+S]) {
					cout << "NO"; return 0; 
				}
			}
		}
	}
//	for (int i = 1;i <= S*2;i++) cout << sid[i] << " "; cout << endl; 
	cout << "YES\n"; 
	for (int i = 1;i <= n;i++) {
		int k = 0; 
		for (int j : v[i]) {
			if (sid[id[i][j]+S] <= sid[id[i][j]]) {
				k = j; 
			}
//			cout << sid[id[i][j]] << " " << sid[id[i][j]+S] << endl; 
//			if (max(sid[id[i][j]], sid[id[i][j]+S]) <= max(sid[id[i][k]], sid[id[i][k]+S])) k = j; 
		}
//		cout << endl; 
		cout << max(1, min(k, (int)1e9)) << " "; 
	}
	return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 42708kb

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:

YES
1 165556251 1 193658790 211550017 685486592 332482851 211550017 728674154 133562624 

result:

wrong answer the 2-th condition is not satisfied

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 17ms
memory: 45660kb

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:

YES
854549869 197498120 508407438 610502845 209356929 706058934 655952999 624132238 550862419 1 654613112 72694954 399757770 396827347 561955959 407919735 779328631 388907784 190412843 657895429 832003778 569593239 492267246 1 718125822 812463588 451830401 281403057 877488996 538715841 664852212 143...

result:

wrong answer the 56-th condition is not satisfied

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%