QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791175#1401. Making Friends is Funmodwwe0 1ms7904kbC++234.0kb2024-11-28 17:18:152024-11-28 17:18:15

Judging History

This is the latest submission verdict.

  • [2024-11-28 17:18:15]
  • Judged
  • Verdict: 0
  • Time: 1ms
  • Memory: 7904kb
  • [2024-11-28 17:18:15]
  • Submitted

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);
        cnt[ {l,r}]=1;
    }
    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();
        int hihi=ds.get(x.a);
        if(ds.dsu[hihi].a!=1)ds.noi(x.b,x.a);
        for(auto f:v[x.a])
        {
            ds.noi(f,x.b);
            if(b[f])ds.noi(f,v[x.b][0]);
        }
        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[ds.get(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;
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 5
Accepted
time: 1ms
memory: 7720kb

input:

1 0

output:

0

result:

ok single line: '0'

Test #2:

score: 5
Accepted
time: 1ms
memory: 5988kb

input:

2 1
2 1

output:

1

result:

ok single line: '1'

Test #3:

score: 5
Accepted
time: 1ms
memory: 7896kb

input:

3 2
2 1
2 3

output:

4

result:

ok single line: '4'

Test #4:

score: 5
Accepted
time: 1ms
memory: 7904kb

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:

77

result:

ok single line: '77'

Test #5:

score: 0
Runtime Error

input:

100 100
78 82
67 85
2 22
88 36
16 50
78 11
53 64
7 68
71 48
27 94
82 22
9 57
35 65
78 70
81 86
22 42
37 19
50 64
98 70
78 31
62 41
33 9
7 100
57 13
71 93
93 15
50 46
66 36
64 62
70 79
17 57
81 74
98 87
62 19
56 10
2 7
10 71
14 25
1 47
39 75
96 3
22 50
57 53
56 30
92 11
58 90
87 99
65 90
85 95
100 25...

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%