QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#107495#5573. Holiday RegiftingFISHER_RE 2ms4120kbC++141.1kb2023-05-21 17:21:452023-05-21 17:21:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-21 17:21:48]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:4120kb
  • [2023-05-21 17:21:45]
  • 提交

answer

#include <bits/stdc++.h>
#define PB push_back
#define EB emplace_back
#define gcd(x, y) __gcd(x, y)
using namespace std;
typedef long long i64;
const int maxn = 10000;
int c[maxn + 5];
vector<int> g[maxn + 5], g2[maxn + 5];
bool vis[maxn + 5];
void dfs(int u) {
	vis[u] = 1;
	for (int v : g[u])
		if (!vis[v]) dfs(v);
}
int ind[maxn + 5];
i64 ca[maxn + 5];
int tp[maxn + 5];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		g[u].PB(v), g2[v].PB(u);
	}
	dfs(1);
	for (int u = 1; u <= n; u++)
		if (vis[u])
			for (int v : g[u]) ind[v]++;
	queue<int> q;
	i64 ans = c[1];
	ca[1] = tp[1] = 1;
	for (int v : g[1])
		if (!(--ind[v])) q.push(v);
	for (int i = 2; !q.empty(); i++) {
		int u = q.front(); q.pop();
		tp[i] = u;
		i64 s = 0;
		for (int v : g2[u]) s += ca[v];
		assert(s > 0);
		int t = c[u] / gcd(s, 1LL * c[u]);
		ca[u] = t * s / c[u];
		ans *= t;
		for (int j = 1; j < i; j++) ca[tp[j]] *= t;
		for (int v : g[u])
			if (!(--ind[v])) q.push(v);
	}
	printf("%lld", ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 4084kb

input:

5 10
4 3 2 2 2
1 3
3 4
1 4
1 5
2 5
2 4
1 2
2 3
3 5
4 5

output:

24

result:

ok 1 number(s): "24"

Test #2:

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

input:

3 0
95 13 77

output:

95

result:

ok 1 number(s): "95"

Test #3:

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

input:

12 14
6 7 17 16 20 14 17 16 6 11 6 14
4 11
3 5
2 5
9 11
7 12
1 3
5 9
3 7
3 8
4 9
1 9
4 7
2 11
1 12

output:

8739360

result:

ok 1 number(s): "8739360"

Test #4:

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

input:

1 0
2

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

50 97
2 2 2 2 2 11 13 7 2 2 2 2 2 2 5 2 5 2 3 2 2 2 2 2 2 2 2 13 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
17 26
17 24
17 38
15 28
23 28
45 50
16 28
7 37
7 31
5 28
2 28
13 28
6 40
3 40
3 7
44 46
11 40
12 28
15 29
15 17
28 49
5 48
6 19
28 41
7 17
27 28
33 38
26 28
2 39
32 40
8 17
17 28
28 42
6 46
2...

output:

68640

result:

ok 1 number(s): "68640"

Test #6:

score: -100
Dangerous Syscalls

input:

500 30000
109 118 125 106 124 114 125 118 110 113 121 132 102 113 117 118 131 104 113 116 113 114 98 134 123 135 124 124 105 105 98 108 118 109 105 117 109 104 109 116 100 112 106 109 113 103 113 108 111 97 125 96 102 106 130 107 111 94 124 104 109 113 101 100 95 105 101 100 106 100 106 86 105 83 11...

output:


result: