QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#130923 | #5522. F*** 3-Colorable Graphs | tselmegkh# | RE | 1ms | 3596kb | C++20 | 1.7kb | 2023-07-25 17:40:34 | 2023-07-25 17:40:36 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;
const int N = 2e5 + 5, inf = 1e9;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define sz(x) (int)x.size()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
vector<vi> a(10004);
int bfs(int i, int xx){
if(a[i].size() == 0) return 0;
bool b[xx + 5];
for(int i = 0; i < xx + 2; i++) b[i] = 0;
int ans = 0;
int cnt = 0;
for(auto x : a[i]){
cnt = 1;
int siz = a[x].size();
if(siz == 0){
if(ans < cnt) ans = cnt;
continue;
}
for(auto y : a[x]){
if(y == i) continue;
if(cnt == 2) cnt = 3;
if(cnt == 1) cnt = 2;
if(b[y] == 1){
return 4;
}
b[y] = 1;
}
if(ans < cnt) ans = cnt;
}
if(cnt != 0) return 3;
return ans;
}
void solve(){
int n, m;
cin >> n >> m;
int ans = 0;
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v;
u--;v--;
a[u].pb(v);
a[v].pb(u);
}
for(int i = 0; i < n; i++){
int tp = bfs(i, n);
if(ans < tp) ans = tp;
}
cout << 6 - ans << endl;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3464kb
input:
2 4 1 3 1 4 2 3 2 4
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
3 5 1 4 2 4 2 5 3 5 3 6
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: -100
Runtime Error
input:
10000 20000 4570 11730 8803 16440 4257 15381 4455 17636 5256 13543 2172 18421 7735 17847 8537 16010 6175 12263 1079 13410 335 15901 3272 16233 7435 11454 4469 13374 1564 13416 1264 13446 7484 14510 8193 12267 628 15585 1388 11398 5444 19958 2059 18140 8947 13188 6214 17707 7940 12253 6726 11508 1839...