Submission #1102466

#TimeUsernameProblemLanguageResultExecution timeMemory
1102466yavuzskarahanKutije (COCI21_kutije)C++11
70 / 70
135 ms1864 KiB
#include <iostream> #include <algorithm> using namespace std; const int N = 1000 + 5; int n, m, q, a, b, arr[N]; struct DSU{ int par[N], stsize[N]; DSU(){ for(int i = 1; i < N; i++) par[i] = i, stsize[i] = 1; } int setfind(int a){ if(par[a] == a) return a; else return par[a] = setfind(par[a]); } void setunion(int a, int b){ a = setfind(a), b = setfind(b); if(a != b){ if(stsize[b] > stsize[a]) swap(a, b); par[b] = par[a]; stsize[a] += stsize[b]; } } }; DSU dsu; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); scanf("%d", &n); scanf("%d", &m); scanf("%d", &q); for(int i = 1; i <= m; i++){ for(int i = 1; i <= n; i++) scanf("%d", &arr[i]); for(int i = 1; i <= n; i++) dsu.setunion(i, arr[i]); } while(q--){ scanf("%d", &a); scanf("%d", &b); if(dsu.setfind(a) == dsu.setfind(b)) printf("DA\n"); else printf("NE\n"); } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d", &m);
      |     ~~~~~^~~~~~~~~~
Main.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
Main.cpp:46:42: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         for(int i = 1; i <= n; i++) scanf("%d", &arr[i]);
      |                                     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~
Main.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%d", &b);
      |         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...