Submission #155207

#TimeUsernameProblemLanguageResultExecution timeMemory
155207stefdascaIzlet (COI19_izlet)C++14
100 / 100
921 ms74668 KiB
#include<bits/stdc++.h> using namespace std; int subtask, n, dist[3002][3002]; int nr; pair<int, int> ans[3002]; vector<int>v[3002]; int tt[3002], color[3002]; int Find(int nod) { if(tt[nod] == nod) return nod; return tt[nod] = Find(tt[nod]); } void Union(int a, int b) { if(Find(a) == Find(b)) return; ans[++nr] = {a, b}; v[a].push_back(b); v[b].push_back(a); a = Find(a); b = Find(b); tt[a] = b; } int cnt[3002], viz[3002]; int newcolor = 0; void give_color(int st, int nod, int p) { if(cnt[color[nod]] == 0 && dist[st][nod] == dist[st][p]) color[st] = color[nod]; if(p != -1) cnt[color[nod]]++; for(int i=0; i<v[nod].size(); i++) { int to = v[nod][i]; if(viz[to] == false || to == p) continue; give_color(st, to, nod); } if(p != -1) cnt[color[nod]]--; } void dfs(int nod, int dad) { viz[nod] = 1; give_color(nod, nod, -1); if(color[nod] == 0) color[nod] = ++newcolor; for(int i = 0; i < v[nod].size(); i++) { int vecin = v[nod][i]; if(vecin == dad) continue; dfs(vecin, nod); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> subtask; cin >> n; for(int i = 1; i <= n; ++i) tt[i] = i; for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) { cin >> dist[i][j]; if(dist[i][j] == 1) Union(i, j); } vector<int>noduri; for(int i = 1; i <= n; ++i) if(Find(i) == i) noduri.push_back(i); for(int i = 0; i < noduri.size(); ++i) { int nod = noduri[i]; for(int j = i+1; j < noduri.size(); ++j) { int vecin = noduri[j]; if(dist[nod][vecin] == 2) Union(nod, vecin); } } cnt[0] = 1; dfs(1, 0); for(int i = 1; i <= n; ++i) cout << color[i] << " "; cout << '\n'; for(int i = 1; i < n; ++i) cout << ans[i].first << " " << ans[i].second << '\n'; return 0; }

Compilation message (stderr)

izlet.cpp: In function 'void give_color(int, int, int)':
izlet.cpp:35:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<v[nod].size(); i++)
                  ~^~~~~~~~~~~~~~
izlet.cpp: In function 'void dfs(int, int)':
izlet.cpp:52:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v[nod].size(); i++)
                    ~~^~~~~~~~~~~~~~~
izlet.cpp: In function 'int main()':
izlet.cpp:79:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < noduri.size(); ++i)
                    ~~^~~~~~~~~~~~~~~
izlet.cpp:82:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = i+1; j < noduri.size(); ++j)
                          ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...