1#include <bits/stdc++.h>2usingnamespace std;3intmain(){4 ios::sync_with_stdio(0);5 cin.tie(0);6int n, m; cin >> n >> m;7vector<int>node(n +1, -1);8vector<vector<int>>adj(n +1);9for(int i =0; i < m; i++){10int a, b; cin >> a >> b;11 adj[a].push_back(b);12 adj[b].push_back(a);13 }14for(int i =1; i <= n; i++){15vector<bool>used(5);16for(int c : adj[i]){17if(node[c] !=-1){18 used[node[c]] =1;19 }20 }21for(int j =1; j <=4; j++){22if(!used[j]){23 node[i] = j;24break;25 }26 }27 }28for(int i =1; i <= n; i++){29 cout << node[i] << (i == n ?"\n":"");30 }31return0;32}
☕
Did this explanation save you time? I'm a Grade 11 student building this free library to make difficult algorithms easier to understand.
Python records executed lines and locals automatically. For selected values in any language, add // @trace i, total on its own valid line; Python uses # @trace i, total.
StatusReady
Output
No run yet.
Diagnostics
No diagnostics yet.
Each run is isolated and has strict limits. Passing one test does not guarantee the judge will accept the solution.