QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#86670#5407. 基础图论练习题GeZhiyuan0 166ms105676kbC++143.0kb2023-03-10 15:23:532023-03-10 15:23:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-10 15:23:55]
  • 评测
  • 测评结果:0
  • 用时:166ms
  • 内存:105676kb
  • [2023-03-10 15:23:53]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 5000 + 5, Mod = 1e9 + 7;
int n = 0, pw2[N * N] = {}, ans[N][N] = {}, ansx = 0;
int tot = 0, dfn[N] = {}, low[N] = {}, ok[N] = {}, col[N] = {}, scc = 0, sz[N] = {};
int sccx = 0, d[N] = {}, totx = 0, verx[N] = {}, colx[N] = {};
vector<vector<int> > G(N);
bitset<N> E[N] = {};
stack<int> stk;
char s[N] = {};

inline void work(int c){
	int u = stk.top(); stk.pop();
	col[u] = c, sz[c] ++, ok[u] = 0;
}

inline void tarjan(int u){
	dfn[u] = low[u] = ++ tot;
	stk.push(u); ok[u] = 1;
	for(int v : G[u]){
		if(!dfn[v]){
			tarjan(v);
			low[u] = min(low[u], low[v]);
		}
		else if(ok[v]) low[u] = min(low[u], dfn[v]);
	}
	if(dfn[u] == low[u]){
		scc ++;
		while(stk.top() != u) work(scc);
		work(scc);
	}
}

inline bool cmp(int u, int v){
	return d[u] < d[v];
}

inline void initx(){
	sccx = 0, memset(colx, -1, sizeof(colx));
	totx = 0, memset(verx, 0, sizeof(verx));
}

inline void solvex(int x){
	for(int u = 1 ; u <= n ; u ++) if(col[x] == col[u] && u != x) verx[totx ++] = u;
	for(int u : G[x]) if(col[u] == col[x]) d[u] --;
	sort(verx, verx + totx, cmp);
	for(int i = 0, m = 0, k = 0 ; i < totx ; i ++){
		m ++, k += d[verx[i]];
		if(m * (m - 1) / 2 == k){
			for(int j = i ; j > i - m ; j --) colx[verx[j]] = sccx;
			m = k = 0, sccx ++;
		}
	}
	int y = 0, w = sccx;
	for(int u : G[x]) if(col[u] == col[x]){
		if(!colx[u] && !y) y = u;
		else w = min(w, colx[u]), ans[max(x, u)][min(x, u)] = scc;
		d[u] ++;
	}
	ans[max(x, y)][min(x, y)] = scc + w;
}

inline void init(){
	for(int u = 1 ; u <= n ; u ++) for(int v = 1 ; v <= n ; v ++) ans[u][v] = E[u][v] = 0;
	for(int u = 1 ; u <= n ; u ++){
		G[u].clear(), d[u] = 0;
		dfn[u] = low[u] = ok[u] = 0;
	}
	for(int c = 1 ; c <= scc ; c ++) sz[c] = 0;
	n = tot = scc = ansx = 0;
	stack<int>().swap(stk);
}

inline void solve(){
	scanf("%d", &n);
	for(int i = 2 ; i <= n ; i ++){
		scanf("%s", s + 1);
		for(int k = 1 ; k <= (i + 2) / 4 ; k ++){
			int x = (s[k] >= '0' && s[k] <= '9') ? (s[k] - '0') : (s[k] - 'A' + 10);
			for(int j = 4 * k - 3 ; j <= 4 * k && j < i ; j ++){
				E[i][j] = (x >> (j - (4 * k - 3))) & 1;
				E[j][i] = E[i][j] ^ 1;
			}
		}
	}
	for(int u = 1 ; u <= n ; u ++) for(int v = 1 ; v <= n ; v ++) if(E[u][v]) G[u].push_back(v), d[v] ++;
	for(int u = 1 ; u <= n ; u ++) if(!dfn[u]) tarjan(u);
	for(int u = 1 ; u <= n ; u ++) if(sz[col[u]] > 1) initx(), solvex(u);
	for(int u = 1 ; u <= n ; u ++) for(int v : G[u]) if(col[u] != col[v]){
		if(col[u] - col[v] > 1 || sz[col[u]] > 1 || sz[col[v]] > 1) ans[max(u, v)][min(u, v)] = scc - (col[u] - col[v]);
		else ans[max(u, v)][min(u, v)] = scc;
	}
	for(int i = 1 ; i <= n ; i ++) for(int j = 1 ; j < i ; j ++) ansx = (ansx + 1ll * pw2[(i - 2) * (i - 1) / 2 + j - 1] * ans[i][j]) % Mod;
	printf("%d\n", ansx);
}

int T = 0;

int main(){
	pw2[0] = 1;
	for(int i = 1 ; i < N * N ; i ++) pw2[i] = pw2[i - 1] * 2 % Mod;
	scanf("%d", &T);
	for(int i = 0 ; i < T ; i ++) init(), solve();
	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: 166ms
memory: 105676kb

input:

10000
100
1
2
2
8
C0
F0
27
78
AE1
C01
511
D87
EF20
3873
2742
73D0
DC9B0
FB2A3
9C011
9B4E0
95DC00
A7B980
F43531
6A6245
5347BE0
1A6C8A1
88E46D6
64CF3AE
D25F63C1
C894E4C3
1C0AFD73
EC1C3F9A
087CE17C0
22149A380
B28038AF1
B9CA21C7F
D78F5307C1
49045489A2
72C4DE6FD1
7713F40D05
EEE8878EEC1
310E62812B1
DA9D5B...

output:

281603732
13
285212670
371842543
50
0
1983
2
268367871
268435455
719476515
32781
2
719476771
75
1572991
2516
0
719476243
371842543
2097143
24703
30719
3113982
719474211
502774846
719476267
719476259
719476259
64360
268697593
719477283
28671
2105215
719476259
371842543
102
78
167
2623487
268435455
13...

result:

wrong answer 3rd numbers differ - expected: '285212672', found: '285212670'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%