結果
問題 | No.2494 Sum within Components |
ユーザー |
![]() |
提出日時 | 2023-10-06 22:11:49 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 73 ms / 2,000 ms |
コード長 | 1,003 bytes |
コンパイル時間 | 1,919 ms |
コンパイル使用メモリ | 30,208 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-26 16:23:47 |
合計ジャッジ時間 | 3,260 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <stdio.h>typedef struct tree {long long v;struct tree *p;} tree;tree *get_root (tree *t) {if (t == NULL || t->p == NULL) {return t;}t->p = get_root(t->p);return t->p;}int main () {int n = 0;int m = 0;long long a = 0LL;int u = 0;int v = 0;int res = 0;long long ans = 1LL;long long mod_num = 998244353LL;tree t[200000] = {};res = scanf("%d", &n);res = scanf("%d", &m);for (int i = 0; i < n; i++) {res = scanf("%lld", &a);t[i].v = a;t[i].p = NULL;}for (int i = 0; i < m; i++) {tree *rt1 = NULL;tree *rt2 = NULL;res = scanf("%d", &u);res = scanf("%d", &v);u--;v--;rt1 = get_root(t+u);rt2 = get_root(t+v);if (rt1 != rt2) {rt1->v += rt2->v;rt1->v %= mod_num;rt2->p = rt1;}}for (int i = 0; i < n; i++) {tree *rt = get_root(t+i);ans *= rt->v;ans %= mod_num;}printf("%lld\n", ans);return 0;}