QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#749178 | #5522. F*** 3-Colorable Graphs | ucup-team2179# | WA | 108ms | 16836kb | C++23 | 2.5kb | 2024-11-14 22:55:45 | 2024-11-14 22:55:55 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define pb push_back
bool debug=1;
#define dbg(x) if(debug)cerr << #x << " = " << (x) <<endl
using namespace std;void ass(string err){cout<<err<<"\n";exit(0);}void ass(int err){cout<<err<<"\n";exit(0);}
typedef pair < long double,long double> pii;
const string COLOR_RESET = "\033[0m", BRIGHT_CYAN = "\033[1;36m", NORMAL_FAINT = "\033[0;2m";
const int maxn=200050;
int par[maxn][22];
int dep[maxn];
int vis[maxn];
int C=19;
vector<int> a[maxn];
void dfs(int u,int pre) //���ڵ����Ϊ1
{
dep[u]=dep[pre]+1;
par[u][0]=pre;
vis[u] = 1;
for(int i=1;i<C;i++)
{
par[u][i]=par[par[u][i-1]][i-1];
}
for(auto p:a[u])
{
if(vis[p]==0)
dfs(p,u);
}
}
int lca(int x,int y)
{
if(dep[y]>dep[x])swap(x,y);
for(int i=C-1;i>=0;i--)
{
if(dep[par[x][i]]>=dep[y])
x=par[x][i];
}
if(x==y)return y;
for(int i=C-1;i>=0;i--)
if(par[x][i]!=par[y][i])
{
x=par[x][i];
y=par[y][i];
}
return par[x][0];
}
int getfa(int u,int k){//����k��
int res=u;
for(int i=C-1;i>=0;i--){
if(k&(1ll<<i)){
res=par[res][i];
}
}
return res;
}
int dis(int u,int v){
return dep[u] + dep[v] - dep[lca(u, v)] * 2;
}
void solve()
{
ios::sync_with_stdio(false);cin.tie(0);mt19937_64 engie(202202052100238523);
int n, m;
cin>>n>>m;
for (int i = 0; i < m;i++){
int u, v;cin>>u>>v;
a[u].pb(v);
a[v].pb(u);
}
dfs(1, 0);
int ans = 3;
for (int i = 1; i <= n * 2;i++)
for(auto p:a[i]){
if(dis(i,p)==3)
ans = 2;
}
cout << ans;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int t=1;
// cin>>t;
while(t--)
{
solve();
cout <<'\n';
}
return 0;
}
//__builtin_popcountl( ) 计算二进制1个数
//cout<<fixed<<setprecision(2);输出小数,四舍六入五取偶
//__builtin_ctz( )返回末尾0的个数
//__builtin_clz( ) 返回前导0的个数
//__builtin_parity( )返回1的个数的奇偶性,偶数返回0
//__builtin_ffs( )返回最后一个1在第几位
//__builtin_sqrt( )快速开平方
//stoll()字符串转为长整形
//点(x,y)的极角atan2(y,x)
//点(x,y)逆时针旋转A度,(x*cosA-y*sinA , x*sinA+y*cosA )
//C(n,k)+C(n,k-1)=(n+1,k)
//string s(str,stridx,strlen) //将字符串str内“始于stridx且长度顶多strlen”
//(从stridx开始往后strlen个字符)的部分作为字符串的初值
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5700kb
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: 2ms
memory: 7804kb
input:
3 5 1 4 2 4 2 5 3 5 3 6
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 13ms
memory: 13272kb
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...
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: -100
Wrong Answer
time: 108ms
memory: 16836kb
input:
9999 199986 8408 17344 1353 16706 3364 17274 9410 10006 9387 19375 9169 18239 3930 12759 4728 11328 5192 17935 7616 19485 3138 12714 8595 18490 6020 15039 9319 17097 7842 16814 7644 18723 2190 10117 3971 13350 232 15408 6984 12842 6988 17196 9744 18905 6759 13371 4115 18937 1842 13513 6245 18736 207...
output:
3
result:
wrong answer 1st numbers differ - expected: '2', found: '3'