Submission #17612755


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
int fa[200005],a[200005],b[200005];
long long s1[200005],s2[200005];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
    int n,m,x,y;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)fa[i]=i,scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)scanf("%d",&b[i]);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        x=find(x),y=find(y);
        fa[x]=y;
    }
    for(int i=1;i<=n;i++)
    {
        int t=find(i);
        s1[t]+=a[i],s2[t]+=b[i];
    }
    for(int i=1;i<=n;i++)
        if(fa[i]==i)
        {
            if(s1[i]!=s2[i]){puts("No");return 0;}
        }
    puts("Yes");
    return 0;
}

Submission Info

Submission Time
Task B - Values
User AzusaCat
Language C++ (GCC 9.2.1)
Score 400
Code Size 705 Byte
Status AC
Exec Time 96 ms
Memory 9044 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:9:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    9 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
./Main.cpp:10:39: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   10 |     for(int i=1;i<=n;i++)fa[i]=i,scanf("%d",&a[i]);
      |                                  ~~~~~^~~~~~~~~~~~
./Main.cpp:11:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   11 |     for(int i=1;i<=n;i++)scanf("%d",&b[i]);
      |                          ~~~~~^~~~~~~~~~~~
./Main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   14 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 44
Set Name Test Cases
Sample 00_sample_00, 00_sample_01, 00_sample_02, 00_sample_03
All 00_sample_00, 00_sample_01, 00_sample_02, 00_sample_03, 01_small_0, 01_small_1, 01_small_2, 01_small_3, 01_small_4, 01_small_5, 01_small_6, 01_small_7, 01_small_8, 01_small_9, 02_large_0, 02_large_1, 02_largecon_0, 02_largecon_1, 02_largecon_2, 02_largecon_3, 02_largecon_4, 02_largecon_5, 02_toolarge_0, 02_toolarge_1, 02_toolarge_2, 02_toolarge_3, 03_few_e_0, 03_few_e_1, 03_few_e_2, 03_few_e_3, 03_few_e_4, 03_few_e_5, 03_is_tree_0, 03_is_tree_1, 03_is_tree_2, 03_is_tree_3, 04_kill_overflow_0, 04_kill_overflow_1, 04_kill_overflow_2, 04_kill_overflow_3, 04_sumequal_0, 04_sumequal_1, 04_sumequal_2, 04_sumequal_3
Case Name Status Exec Time Memory
00_sample_00 AC 22 ms 3472 KiB
00_sample_01 AC 2 ms 3608 KiB
00_sample_02 AC 3 ms 3632 KiB
00_sample_03 AC 3 ms 3472 KiB
01_small_0 AC 2 ms 3640 KiB
01_small_1 AC 2 ms 3632 KiB
01_small_2 AC 2 ms 3608 KiB
01_small_3 AC 2 ms 3604 KiB
01_small_4 AC 2 ms 3596 KiB
01_small_5 AC 2 ms 3524 KiB
01_small_6 AC 2 ms 3640 KiB
01_small_7 AC 3 ms 3640 KiB
01_small_8 AC 3 ms 3636 KiB
01_small_9 AC 2 ms 3664 KiB
02_large_0 AC 59 ms 7404 KiB
02_large_1 AC 33 ms 4976 KiB
02_largecon_0 AC 83 ms 5308 KiB
02_largecon_1 AC 81 ms 5516 KiB
02_largecon_2 AC 82 ms 5212 KiB
02_largecon_3 AC 61 ms 4692 KiB
02_largecon_4 AC 87 ms 5688 KiB
02_largecon_5 AC 76 ms 4980 KiB
02_toolarge_0 AC 95 ms 9044 KiB
02_toolarge_1 AC 91 ms 9044 KiB
02_toolarge_2 AC 88 ms 8932 KiB
02_toolarge_3 AC 96 ms 8928 KiB
03_few_e_0 AC 41 ms 6980 KiB
03_few_e_1 AC 53 ms 8140 KiB
03_few_e_2 AC 45 ms 7320 KiB
03_few_e_3 AC 55 ms 8252 KiB
03_few_e_4 AC 56 ms 8412 KiB
03_few_e_5 AC 48 ms 7896 KiB
03_is_tree_0 AC 71 ms 7196 KiB
03_is_tree_1 AC 62 ms 6840 KiB
03_is_tree_2 AC 58 ms 6700 KiB
03_is_tree_3 AC 62 ms 6752 KiB
04_kill_overflow_0 AC 87 ms 8000 KiB
04_kill_overflow_1 AC 67 ms 6468 KiB
04_kill_overflow_2 AC 72 ms 6536 KiB
04_kill_overflow_3 AC 66 ms 6352 KiB
04_sumequal_0 AC 49 ms 6900 KiB
04_sumequal_1 AC 36 ms 5376 KiB
04_sumequal_2 AC 18 ms 4452 KiB
04_sumequal_3 AC 30 ms 5488 KiB