QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153793#6354. 4PhantomThresholdTL 3ms8608kbC++201.6kb2023-08-30 23:59:462023-08-30 23:59:48

Judging History

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

  • [2023-08-30 23:59:48]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:8608kb
  • [2023-08-30 23:59:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace K4{
	typedef long long ll;
	const int maxn=100000;
	int n,m;
	vector<int> g[maxn+50];
	int deg[maxn+50];
	void init(){
		cin >> n >> m;
		for (int i=1;i<=m;i++){
			int x,y;
			cin >> x >> y;
			g[x].push_back(y);
			g[y].push_back(x);
			deg[x]++;
			deg[y]++;
		}
	}
	ll gao(ll n,vector<vector<int>> G){
		ll ans=0;
		vector< bitset<maxn+1> > ok(n+1);
		for (int u=1;u<=n;u++){
			for (auto v:G[u]) ok[u][v]=1;	
		}
		for (int u=1;u<=n;u++){
			for (auto v:G[u]){
				ans+=(ok[u]&ok[v]).count();
			}
		}
		return ans;
	}
	vector<int> G[maxn+50];
	ll solve(){
		ll ans=0;
		vector<int> order(n+5);
		for (int i=1;i<=n;i++) order[i]=i;
		sort(order.begin()+1,order.begin()+n+1,
			[&](int x,int y){
				return (deg[x]==deg[y])?(x<y):(deg[x]<deg[y]);	
			}
		);
		vector<int> rk(n+5);
		for (int i=1;i<=n;i++) rk[order[i]]=i;
		for (int u=1;u<=n;u++){
			for (auto v:g[u]) if (rk[u]<rk[v]){
				G[rk[u]].push_back(rk[v]);	
			}
		}
		for (int i=1;i<=n;i++) sort(G[i].begin(),G[i].end());
		
		vector<vector<int>> subG(n+1);
		for (int u=1;u<=n;u++){
			int top=0;
			vector<int> id(n+1);
			for (auto v:G[u]) id[v]=++top;
			
			vector<vector<int>> tag(n+1);
			for (auto v:G[u]){
				for (auto w:G[v]) tag[w].push_back(v);
				for (auto w:tag[v]){
					subG[id[w]].push_back(id[v]);
					subG[id[v]].push_back(id[w]);
				}
				ans=ans+gao(top,subG)/3;
			}
			for (int i=1;i<=top;i++) subG[i].clear();
		}
		return ans;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	K4::init();
	cout << K4::solve()/2 << "\n";
	return 0;	
}

详细

Test #1:

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

input:

5 9
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

4 0

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

50 50
28 35
12 24
31 50
10 24
21 44
5 31
23 36
31 45
6 39
4 8
13 37
42 48
17 45
19 33
12 21
19 32
16 43
12 47
25 31
40 48
8 49
43 48
6 42
27 34
13 39
17 40
13 35
3 49
20 24
5 12
43 44
15 37
24 27
8 43
4 22
17 38
28 47
29 46
3 15
9 49
1 41
43 45
3 6
37 48
13 30
11 43
8 25
33 38
16 32
32 41

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: -100
Time Limit Exceeded

input:

100 4900
64 78
3 13
93 96
48 64
34 64
5 76
66 74
44 78
17 20
30 73
5 34
24 100
23 65
4 70
22 95
47 70
6 89
15 70
70 82
88 90
29 80
27 64
16 59
28 99
67 68
85 99
37 85
8 46
71 78
40 95
6 21
27 66
16 89
11 83
17 57
19 36
21 70
27 86
27 45
5 56
10 64
23 33
87 91
37 40
21 55
75 79
54 96
3 77
70 78
36 93...

output:


result: