QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#298803 | #559. 原力 | DanielDingDang | 100 ✓ | 156ms | 37324kb | C++14 | 2.0kb | 2024-01-06 14:51:37 | 2024-01-06 14:53:51 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <cmath>
using namespace std;
#define N 50050
#define M 200050
#define mod 1000000007
typedef long long ll;
int n, m, head[N], to[M], nxt[M], val[M], opp[M], cnt;
int du[N], a[N], la, vis[N];
char opt[5];
map<int, ll> dis[N][3];
inline void add(int u, int v, int w, int o) {
to[++cnt] = v; nxt[cnt] = head[u]; head[u] = cnt; val[cnt] = w; opp[cnt] = o;
}
int main() {
scanf("%d%d", &n, &m);
int i, x, y, z, o, S = sqrt(n);
for (i = 1; i <= m; i++) {
scanf("%d%d%d%s", &x, &y, &z, opt);
o = (opt[0] == 'R') ? 0 : (opt[0] == 'G') ? 1 : 2;
dis[x][o][y] += z;
dis[y][o][x] += z;
add(x, y, z, o);
add(y, x, z, o);
du[x]++; du[y]++;
}
ll ans = 0;
for (i = 1; i <= n; i++) {
if (du[i] > S) a[++la] = i;
}
int j, k;
for (i = 1; i <= la; i++) {
x = a[i];
for (j = 1; j <= la; j++) {
if (dis[x][0][a[j]]) {
y = a[j];
ll t1 = dis[x][0][y];
for (k = 1; k <= la; k++) {
if (dis[y][1][a[k]]) {
z = a[k];
ans = (ans + t1 * dis[y][1][z] % mod * dis[z][2][x]) % mod;
}
}
}
}
}
for (x = 1; x <= n; x++) {
if (du[x] <= S) {
vis[x] = 1;
for (i = head[x]; i; i = nxt[i]) {
if (!vis[to[i]]) {
ll t = val[i];
for (j = nxt[i]; j; j = nxt[j]) {
if (!vis[to[j]] && opp[i] != opp[j] && to[i] != to[j]) {
ans = (ans + t * val[j] % mod * dis[to[i]][3 - opp[i] - opp[j]][to[j]]) % mod;
}
}
}
}
}
}
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 6ms
memory: 11588kb
input:
85 1024 26 70 3 B 75 47 7 G 23 81 7 R 70 68 7 B 51 26 9 R 41 72 8 R 31 46 2 G 82 7 5 G 6 15 2 B 50 44 4 R 41 17 3 G 58 41 8 B 82 22 4 R 9 39 8 B 54 61 7 R 23 29 6 G 68 52 5 R 28 57 7 G 36 39 4 G 74 83 2 B 58 14 4 G 30 39 1 R 38 76 5 G 19 8 3 R 36 48 5 B 71 76 4 B 33 65 8 R 53 81 10 B 28 72 8 G 21 52...
output:
90693
result:
ok 1 number(s): "90693"
Test #2:
score: 10
Accepted
time: 70ms
memory: 13032kb
input:
95 16384 73 45 5 B 57 95 31 G 52 94 52 R 54 45 98 G 81 40 96 R 37 1 15 R 81 91 13 B 66 4 81 B 89 93 43 R 40 23 27 G 30 68 24 G 85 32 98 G 82 86 21 B 24 18 39 R 60 39 29 R 62 74 32 B 77 15 59 R 77 13 59 G 10 53 98 R 24 32 99 G 80 70 52 R 77 49 29 G 19 76 88 G 25 2 55 B 61 92 18 B 44 50 53 R 70 75 1 B...
output:
34773089
result:
ok 1 number(s): "34773089"
Test #3:
score: 10
Accepted
time: 156ms
memory: 15716kb
input:
99 100000 14 25 53839 G 6 22 555681 G 14 58 127533 B 93 30 685857 G 86 68 720946 G 14 59 657691 B 40 57 159703 R 59 83 309777 G 7 99 151251 B 57 77 769566 G 11 4 406698 R 14 60 739074 G 18 51 934158 R 39 14 237859 B 59 70 810047 G 14 35 733152 R 38 19 549269 R 37 79 413532 B 87 7 30363 B 83 7 795910...
output:
300572702
result:
ok 1 number(s): "300572702"
Test #4:
score: 10
Accepted
time: 67ms
memory: 24352kb
input:
4999 50000 3515 625 2 G 1458 3602 1 G 2400 3744 8 R 625 4677 10 G 3602 4385 5 B 4716 2535 7 B 1057 1829 7 R 3691 3073 7 R 1583 1852 7 G 4427 153 10 G 4774 1298 6 R 836 2610 3 G 2022 2207 4 G 3481 4450 6 R 1477 3602 3 G 2399 4851 7 G 3073 3532 9 G 795 2764 9 B 3053 2908 6 G 3979 3239 8 R 4877 863 4 G...
output:
7585569
result:
ok 1 number(s): "7585569"
Test #5:
score: 10
Accepted
time: 51ms
memory: 24148kb
input:
9999 50000 8342 1822 1 R 2454 7542 91 R 4747 6417 54 G 6114 790 56 G 2423 3828 71 G 9534 6417 66 G 6907 9508 93 B 7593 2449 100 B 7037 6417 73 B 8149 1505 10 G 728 5819 91 R 6417 5132 58 B 8046 5108 25 G 9320 4005 13 G 2577 6417 92 G 1154 5596 45 B 3115 8046 61 G 6417 3191 14 B 6417 2556 92 R 6417 6...
output:
305858005
result:
ok 1 number(s): "305858005"
Test #6:
score: 10
Accepted
time: 34ms
memory: 19804kb
input:
39999 50000 711 20333 781142 R 23113 14256 146398 G 36974 20333 525277 R 36111 33004 752115 B 8782 20662 280729 G 25188 9984 379947 B 20333 35283 24241 R 29867 20333 316858 G 17063 20333 204821 B 32466 11296 757600 G 18780 39492 833820 R 20333 32132 963038 G 6250 38375 764880 R 11296 35435 774020 G ...
output:
910002950
result:
ok 1 number(s): "910002950"
Test #7:
score: 10
Accepted
time: 111ms
memory: 32040kb
input:
20000 100000 16355 4798 940 G 13008 13907 349 G 4798 17727 621 R 13008 5194 836 G 13008 18776 111 G 4739 13008 599 B 4798 7237 850 G 13008 6737 228 G 13008 14079 199 B 2532 208 645 B 4798 15196 267 B 8734 18039 668 G 17823 17093 141 G 16325 15294 171 R 13008 15936 950 G 13806 13008 855 R 4104 11188 ...
output:
74652463
result:
ok 1 number(s): "74652463"
Test #8:
score: 10
Accepted
time: 119ms
memory: 37324kb
input:
30000 100000 3757 12254 1505 B 7935 28786 71 B 15119 2468 960 G 12418 15335 468 G 3378 220 534 B 14160 5855 494 B 20502 10202 284 G 1655 11330 36 R 11744 14165 388 R 10444 6281 1463 R 18863 14050 847 G 5311 511 1317 B 6734 75 1224 B 21061 7652 1846 R 22703 14160 1073 B 11890 6592 1002 B 25235 21600 ...
output:
600759360
result:
ok 1 number(s): "600759360"
Test #9:
score: 10
Accepted
time: 80ms
memory: 28508kb
input:
40000 100000 677 7952 47133 B 26245 25217 20330 B 27073 5097 79391 B 24358 23616 90279 G 32570 33531 95478 B 11357 21106 34680 R 11974 27868 17701 R 12937 16890 53472 G 6967 7513 35198 G 27987 11357 58966 B 35641 7203 95467 G 11357 19348 86505 R 27597 34548 53863 R 31334 11357 28148 G 11303 23560 83...
output:
773736079
result:
ok 1 number(s): "773736079"
Test #10:
score: 10
Accepted
time: 93ms
memory: 32096kb
input:
50000 100000 6823 20867 761119 R 15633 41381 594787 G 15521 17722 827117 B 22016 5255 111472 G 33162 21404 102291 G 20232 39357 226738 G 31698 23330 668274 R 41381 11664 404107 B 4517 4277 115972 B 185 719 279579 G 16463 47896 310079 B 3434 32893 16111 B 44769 6560 943760 G 44874 41381 183542 B 1996...
output:
674393235
result:
ok 1 number(s): "674393235"