Submission #129631

#TimeUsernameProblemLanguageResultExecution timeMemory
129631pzdbaIzlet (COI19_izlet)C++14
0 / 100
848 ms53456 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; int a[3002][3002], p[3002], cnt[3002]; vector<pii> edge; int root(int a){ return p[a] == a?a:(p[a]=root(p[a])); } void merge(int a, int b){ a = root(a), b = root(b); if(a != b) p[a] = b; } int main(){ int t; scanf("%d", &t); int n; scanf("%d", &n); for(int i=1;i<=n;i++) p[i] = i; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ scanf("%d", &a[i][j]); if(a[i][j] == 1 && root(i) != root(j)){ edge.push_back(pii(i, j)); merge(i, j); } } } int j = 1; for(int i=1;i<=n;i++){ if(p[i] == i) cnt[i] = j++; } for(int i=1;i<=n;i++) printf("%d ", cnt[root(i)]); printf("\n"); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(a[i][j] == 2 && root(i) != root(j)){ edge.push_back(pii(i, j)); merge(i, j); } } } for(int i=0;i<n-1;i++) printf("%d %d\n", edge[i].first, edge[i].second); }

Compilation message (stderr)

izlet.cpp: In function 'int main()':
izlet.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &t);
     ~~~~~^~~~~~~~~~
izlet.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
izlet.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &a[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...