| Task: | Building Teams |
| Sender: | aalto26bm_042 |
| Submission time: | 2026-09-07 16:40:41 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.01 s | details |
| #2 | WRONG ANSWER | 0.01 s | details |
| #3 | WRONG ANSWER | 0.01 s | details |
| #4 | WRONG ANSWER | 0.01 s | details |
| #5 | WRONG ANSWER | 0.01 s | details |
| #6 | WRONG ANSWER | 0.12 s | details |
| #7 | WRONG ANSWER | 0.12 s | details |
| #8 | WRONG ANSWER | 0.12 s | details |
| #9 | WRONG ANSWER | 0.12 s | details |
| #10 | ACCEPTED | 0.12 s | details |
| #11 | WRONG ANSWER | 0.01 s | details |
| #12 | WRONG ANSWER | 0.01 s | details |
Compiler report
input/code.cpp: In function 'long long int MAIN()':
input/code.cpp:76:9: warning: unused variable 'num_component' [-Wunused-variable]
76 | int num_component=0;
| ^~~~~~~~~~~~~Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define die(x) return cout << x << endl, 0
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define SZ(x) ((int)(x).size())
typedef long double ld;
typedef long long ll;
int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
int to_int(string sconvert){stringstream geek(sconvert);int xconvert = 0; geek >> xconvert; return xconvert;}
const int MAXN=200000+30,MAX_LOG=40,INF=1e18+10,MOD=1e9+7;
const double PI = acos(-1);
int mod(int x) { return (x % MOD + MOD) % MOD; }
int power(int x,int y){
if(y==0)return 1;
int c=power(x,y/2);
c=(c*c)%MOD;
if(y%2)c=(c*x)%MOD;
return c;
}
int n, t;
vector<int> g[MAXN];
int visited[MAXN];
int color[MAXN];
int max_color = 1;
int is_impossible = 0;
vector<pair<int,int>> edges;
int dfs(int v, int root){
visited[v]=1;
if(g[v].size() == 1 && v != root){
// cout<<v<<" kk"<<g[v].size()<<endl;
color[v] = 1;
return 1;
}
int ones = 0;
int twos = 0;
for(int u:g[v]){
if(!visited[u]){
int c = dfs(u, root);
if (c == 1) ones++;
else twos ++;
}
}
// cout<<ones<<" "<<twos<<"--- "<<v<<endl;
if (ones>0 && twos >0){
is_impossible=1;
return 1;
}
else if (ones>=0){
color[v]=2;
return 2;
}
else{
color[v]=1;
return 1;
}
}
int MAIN(){
int n, m;
cin>>n>>m;
for(int i=0;i<m;i++){
int u, v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
int num_component=0;
for(int i=1;i<=n;i++){
if(!visited[i]){
dfs(i, i);
}
}
if(is_impossible){
cout<<"IMPOSSIBLE";
return 0;
}
for (int i = 1; i <= n; i++){
cout<<color[i]<<" ";
}
return 0;
}
int32_t main(){
IOS;
int t=1;
// cin>>t;
while(t--)MAIN();
return 0;
}Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 3 4 8 10 3 7 1 8 ... |
| correct output |
|---|
| 1 1 1 2 2 1 2 2 2 1 |
| user output |
|---|
| 2 2 2 2 2 2 2 2 2 2 |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 1 3 8 10 2 4 6 8 ... |
| correct output |
|---|
| 1 1 2 2 1 1 1 2 1 1 |
| user output |
|---|
| 2 2 2 2 2 2 2 2 2 2 |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 7 10 3 10 9 10 2 10 ... |
| correct output |
|---|
| 1 2 2 1 1 1 2 1 2 1 |
| user output |
|---|
| 2 2 2 2 2 2 2 2 2 2 |
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 2 4 2 10 7 10 4 6 ... |
| correct output |
|---|
| 1 2 1 1 2 2 2 1 2 1 |
| user output |
|---|
| 2 2 2 2 2 2 2 2 2 2 |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 3 5 8 10 9 10 1 8 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| 2 2 2 2 2 2 2 2 2 2 |
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 100000 200000 47355 96505 90709 92058 735 80715 91802 94265 ... |
| correct output |
|---|
| 1 2 2 1 2 1 1 1 2 2 1 2 1 1 1 ... |
| user output |
|---|
| IMPOSSIBLE |
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 100000 200000 59991 95794 95150 96051 78453 94730 90411 95523 ... |
| correct output |
|---|
| 1 1 1 2 2 1 1 2 1 2 1 2 2 2 1 ... |
| user output |
|---|
| IMPOSSIBLE |
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 100000 200000 89827 96402 65137 86792 80965 94708 19479 48078 ... |
| correct output |
|---|
| 1 2 1 1 2 1 2 2 2 1 2 1 1 2 1 ... |
| user output |
|---|
| IMPOSSIBLE |
Test 9
Verdict: WRONG ANSWER
| input |
|---|
| 100000 200000 72952 83723 66197 70052 2949 52160 55753 95651 ... |
| correct output |
|---|
| 1 1 2 2 2 1 1 2 2 2 2 2 1 2 1 ... |
| user output |
|---|
| IMPOSSIBLE |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 100000 200000 38942 96755 70049 82663 7746 72732 87819 99029 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
Test 11
Verdict: WRONG ANSWER
| input |
|---|
| 5 4 1 2 3 4 4 5 5 3 |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| 2 1 2 2 2 |
Test 12
Verdict: WRONG ANSWER
| input |
|---|
| 4 5 1 2 1 4 2 3 2 4 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| 2 2 2 2 |
