QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#791142 | #1401. Making Friends is Fun | modwwe | 0 | 2ms | 9964kb | C++23 | 3.8kb | 2024-11-28 17:06:27 | 2024-11-28 17:06:32 |
Judging History
answer
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf = 1e9;
const ll mod2 = 1e9 + 7;
const int mod1 = 998244353;
const ll base=67;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int add(int x,int y)
{
if(x+y>=mod2) x-=mod2;
if(x+y<0)x+=mod2;
return x+y;
}
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a, b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,t,lim,w,l,r ;
int kk;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
// modwwe
phongbeo();
// checktime
}
int c[100001];
bool b[100001];
vector<int> v[100001];
struct skibidi
{
ib dsu[100001];
vector<int> cc[100001];
void reset()
{
for(int i=1; i<=n; i++)
dsu[i]= {1,i},cc[i].pb({i});
}
int get(int x)
{
if(dsu[x].b==x) return x;
return dsu[x].b=get(dsu[x].b);
}
void noi(int x,int y)
{
x=get(x);
y=get(y);
if(x==y) return;
if(dsu[x].a<dsu[y].a)swap(x,y);
dsu[x].a+=dsu[y].a;
dsu[y].b=x;
for(auto f:cc[y])
cc[x].pb(f);
vector<int>().swap(cc[y]);
}
} ds;
map<pair<int,int>,bool>cnt;
void phongbeo()
{
cin>>n>>m;
/// kieu ko tim du 2 con thi ko noi dc
stack<ib> s;
for(int i=1; i<=m; i++)
{
cin>>l>>r;
c[l]++;
v[l].pb(r);
}
for(int i=1; i<=n; i++)
if(c[i]>=2)
s.push({i,v[i][0]}),b[i]=1;
ds.reset();
while(!s.empty())
{
ib x=s.top();
s.pop();
for(auto f:v[x.a])
{
ds.noi(f,x.b);
}
for(auto f:v[x.a])
{
if(ds.dsu[ds.get(f)].a>=3&&!b[f])
{
b[f]=1;
s.push({f,ds.get(f)});
}
else if(!b[f])
{
for(auto g:ds.cc[f])
if(g!=f&&cnt[ {f,g}]==0)
{
c[f]++;
if(c[f]>=2)
{
b[f]=1;
s.push({f,ds.get(f)});
break;
}
}
}
}
}
for(int i=1; i<=n; i++)
{
if(ds.dsu[i].b==i)
{
s4+=ds.dsu[i].a*(ds.dsu[i].a-1);
}
for(auto x:v[i])
if(ds.get(x)!=ds.get(i))
s4++;
}
cout<<s4;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 7724kb
input:
1 0
output:
0
result:
ok single line: '0'
Test #2:
score: 5
Accepted
time: 0ms
memory: 7980kb
input:
2 1 2 1
output:
1
result:
ok single line: '1'
Test #3:
score: 5
Accepted
time: 2ms
memory: 9780kb
input:
3 2 2 1 2 3
output:
4
result:
ok single line: '4'
Test #4:
score: 0
Wrong Answer
time: 1ms
memory: 9964kb
input:
13 12 1 2 2 3 3 4 1 5 5 6 6 7 7 8 8 9 9 10 11 1 12 11 13 11
output:
49
result:
wrong answer 1st lines differ - expected: '77', found: '49'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%