답안 #1106045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106045 2024-10-29T03:21:32 Z modwwe Election Campaign (JOI15_election_campaign) C++17
100 / 100
157 ms 41668 KB
#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".ans","w",stdout)
#define pb push_back
#define mask(i) (1<<i)
#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 = 1e18;
const int mod2 = 1e9+7;
const int  mod1 = 998244353;
const int base=67;
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, 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,limit,w,l,r,last,root,cost;
int kk,invf;
int el = 19;

main()
{
    if(fopen(task".inp","r"))
    {
        fin(task);
        //fou(task);
    }
    NHP
    /// cin>>s1;
    // modwwe
    phongbeo(),down
    // checktime
}
int dp[100001];
int st[17][100001];
int in[100001];
int ou[100001];
vector<int>v[100001];
vector<ic> v2[100001];
struct fen_wick
{
    int bit[100001];
    void upd(int x,int y,int z)
    {
        y++;
        for(x; x<=n; x+=x&-x)
            bit[x]+=z;
        for(y; y<=n; y+=y&-y)
            bit[y]-=z;
    }
    int get(int x)
    {
        int s=0;
        for(x; x; x-=x&-x)
            s+=bit[x];
        return s;
    }
} fen;
bool check(int x,int y)
{
    if(in[x]<=in[y]&&ou[x]>=in[y]) return 0;
    else return 1;
}
int lca(int x,int y)
{
    if(!check(x,y)) return x;
    for(int j=16; j>=0; --j)
        if(check(st[j][x],y))
            x=st[j][x];
    return st[0][x];
}
void dfs(int x,int y)
{
    st[0][x]=y;
    in[x]=++dem;
    for(auto f:v[x])
        if(f!=y)
            dfs(f,x);
    ou[x]=dem;
}
void dfs2(int x,int y)
{
    for(auto f:v[x])
        if(f!=y)
            dfs2(f,x),
                 dp[x]+=dp[f],
                        fen.upd(in[f],ou[f],-dp[f]);
    /// if choose con cua f thi -dpf :D
    s5=0;
    for(auto f:v2[x])
        s2=fen.get(in[f.a])+fen.get(in[f.b])+f.c,
        s5=max(s5,s2);
    /// choose f.a and f.b +?cost
    fen.upd(in[x],in[x],dp[x]);
    dp[x]+=s5;
    for(auto f:v[x])
        if(f!=y)
        {
            fen.upd(in[x]+1,ou[x],dp[f]);
            ///+x-x=0
            /*
            fen.upd(in[f],ou[f],dp[f]);
            fen.upd(in[f],ou[f],-dp[f]);
            */
        }
}
void phongbeo()
{
    cin>>n;
    for(int i=2; i<=n; i++)
    {
        cin>>l>>r;
        v[l].pb(r);
        v[r].pb(l);
    }
    dfs(1,0);
    ou[0]=dem;
    for(int i=1; i<17; i++)
        for(int j=1; j<=n; j++)
            st[i][j]=st[i-1][st[i-1][j]];
    cin>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>l>>r>>s2;
        v2[lca(l,r)].pb({l,r,s2});
    }
    dfs2(1,0);
    cout<<dp[1];
}

Compilation message

election_campaign.cpp:72:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   72 | main()
      | ^~~~
election_campaign.cpp: In member function 'void fen_wick::upd(long long int, long long int, long long int)':
election_campaign.cpp:97:13: warning: statement has no effect [-Wunused-value]
   97 |         for(x; x<=n; x+=x&-x)
      |             ^
election_campaign.cpp:99:13: warning: statement has no effect [-Wunused-value]
   99 |         for(y; y<=n; y+=y&-y)
      |             ^
election_campaign.cpp: In member function 'long long int fen_wick::get(long long int)':
election_campaign.cpp:105:13: warning: statement has no effect [-Wunused-value]
  105 |         for(x; x; x-=x&-x)
      |             ^
election_campaign.cpp: In function 'int main()':
election_campaign.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
election_campaign.cpp:76:9: note: in expansion of macro 'fin'
   76 |         fin(task);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 20816 KB Output is correct
2 Correct 3 ms 20816 KB Output is correct
3 Correct 3 ms 20984 KB Output is correct
4 Correct 4 ms 20816 KB Output is correct
5 Correct 42 ms 26448 KB Output is correct
6 Correct 33 ms 35220 KB Output is correct
7 Correct 50 ms 32328 KB Output is correct
8 Correct 44 ms 26696 KB Output is correct
9 Correct 54 ms 30556 KB Output is correct
10 Correct 36 ms 26768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 20816 KB Output is correct
2 Correct 3 ms 20816 KB Output is correct
3 Correct 4 ms 20976 KB Output is correct
4 Correct 92 ms 41088 KB Output is correct
5 Correct 96 ms 41032 KB Output is correct
6 Correct 74 ms 41040 KB Output is correct
7 Correct 94 ms 41032 KB Output is correct
8 Correct 92 ms 41196 KB Output is correct
9 Correct 80 ms 41128 KB Output is correct
10 Correct 94 ms 41032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 20816 KB Output is correct
2 Correct 3 ms 20816 KB Output is correct
3 Correct 4 ms 20976 KB Output is correct
4 Correct 92 ms 41088 KB Output is correct
5 Correct 96 ms 41032 KB Output is correct
6 Correct 74 ms 41040 KB Output is correct
7 Correct 94 ms 41032 KB Output is correct
8 Correct 92 ms 41196 KB Output is correct
9 Correct 80 ms 41128 KB Output is correct
10 Correct 94 ms 41032 KB Output is correct
11 Correct 12 ms 22784 KB Output is correct
12 Correct 95 ms 41288 KB Output is correct
13 Correct 100 ms 41352 KB Output is correct
14 Correct 79 ms 41288 KB Output is correct
15 Correct 96 ms 41296 KB Output is correct
16 Correct 69 ms 41288 KB Output is correct
17 Correct 108 ms 41288 KB Output is correct
18 Correct 94 ms 41288 KB Output is correct
19 Correct 81 ms 41668 KB Output is correct
20 Correct 94 ms 41332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 31804 KB Output is correct
2 Correct 77 ms 40936 KB Output is correct
3 Correct 135 ms 37696 KB Output is correct
4 Correct 96 ms 32456 KB Output is correct
5 Correct 154 ms 37056 KB Output is correct
6 Correct 88 ms 33072 KB Output is correct
7 Correct 113 ms 36540 KB Output is correct
8 Correct 144 ms 31932 KB Output is correct
9 Correct 73 ms 41072 KB Output is correct
10 Correct 115 ms 36056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 20816 KB Output is correct
2 Correct 3 ms 20816 KB Output is correct
3 Correct 3 ms 20984 KB Output is correct
4 Correct 4 ms 20816 KB Output is correct
5 Correct 42 ms 26448 KB Output is correct
6 Correct 33 ms 35220 KB Output is correct
7 Correct 50 ms 32328 KB Output is correct
8 Correct 44 ms 26696 KB Output is correct
9 Correct 54 ms 30556 KB Output is correct
10 Correct 36 ms 26768 KB Output is correct
11 Correct 4 ms 21072 KB Output is correct
12 Correct 4 ms 20980 KB Output is correct
13 Correct 4 ms 21072 KB Output is correct
14 Correct 4 ms 21072 KB Output is correct
15 Correct 4 ms 21072 KB Output is correct
16 Correct 4 ms 21308 KB Output is correct
17 Correct 4 ms 21072 KB Output is correct
18 Correct 4 ms 20976 KB Output is correct
19 Correct 4 ms 21072 KB Output is correct
20 Correct 5 ms 20976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 20816 KB Output is correct
2 Correct 3 ms 20816 KB Output is correct
3 Correct 3 ms 20984 KB Output is correct
4 Correct 4 ms 20816 KB Output is correct
5 Correct 42 ms 26448 KB Output is correct
6 Correct 33 ms 35220 KB Output is correct
7 Correct 50 ms 32328 KB Output is correct
8 Correct 44 ms 26696 KB Output is correct
9 Correct 54 ms 30556 KB Output is correct
10 Correct 36 ms 26768 KB Output is correct
11 Correct 3 ms 20816 KB Output is correct
12 Correct 3 ms 20816 KB Output is correct
13 Correct 4 ms 20976 KB Output is correct
14 Correct 92 ms 41088 KB Output is correct
15 Correct 96 ms 41032 KB Output is correct
16 Correct 74 ms 41040 KB Output is correct
17 Correct 94 ms 41032 KB Output is correct
18 Correct 92 ms 41196 KB Output is correct
19 Correct 80 ms 41128 KB Output is correct
20 Correct 94 ms 41032 KB Output is correct
21 Correct 12 ms 22784 KB Output is correct
22 Correct 95 ms 41288 KB Output is correct
23 Correct 100 ms 41352 KB Output is correct
24 Correct 79 ms 41288 KB Output is correct
25 Correct 96 ms 41296 KB Output is correct
26 Correct 69 ms 41288 KB Output is correct
27 Correct 108 ms 41288 KB Output is correct
28 Correct 94 ms 41288 KB Output is correct
29 Correct 81 ms 41668 KB Output is correct
30 Correct 94 ms 41332 KB Output is correct
31 Correct 102 ms 31804 KB Output is correct
32 Correct 77 ms 40936 KB Output is correct
33 Correct 135 ms 37696 KB Output is correct
34 Correct 96 ms 32456 KB Output is correct
35 Correct 154 ms 37056 KB Output is correct
36 Correct 88 ms 33072 KB Output is correct
37 Correct 113 ms 36540 KB Output is correct
38 Correct 144 ms 31932 KB Output is correct
39 Correct 73 ms 41072 KB Output is correct
40 Correct 115 ms 36056 KB Output is correct
41 Correct 4 ms 21072 KB Output is correct
42 Correct 4 ms 20980 KB Output is correct
43 Correct 4 ms 21072 KB Output is correct
44 Correct 4 ms 21072 KB Output is correct
45 Correct 4 ms 21072 KB Output is correct
46 Correct 4 ms 21308 KB Output is correct
47 Correct 4 ms 21072 KB Output is correct
48 Correct 4 ms 20976 KB Output is correct
49 Correct 4 ms 21072 KB Output is correct
50 Correct 5 ms 20976 KB Output is correct
51 Correct 157 ms 32204 KB Output is correct
52 Correct 94 ms 41292 KB Output is correct
53 Correct 120 ms 36536 KB Output is correct
54 Correct 95 ms 32308 KB Output is correct
55 Correct 101 ms 32464 KB Output is correct
56 Correct 93 ms 41288 KB Output is correct
57 Correct 102 ms 36692 KB Output is correct
58 Correct 100 ms 32336 KB Output is correct
59 Correct 112 ms 32312 KB Output is correct
60 Correct 94 ms 41592 KB Output is correct
61 Correct 112 ms 36908 KB Output is correct
62 Correct 103 ms 33848 KB Output is correct
63 Correct 106 ms 32428 KB Output is correct
64 Correct 95 ms 41288 KB Output is correct
65 Correct 131 ms 37724 KB Output is correct
66 Correct 110 ms 31720 KB Output is correct
67 Correct 105 ms 33232 KB Output is correct
68 Correct 94 ms 41288 KB Output is correct
69 Correct 115 ms 35264 KB Output is correct
70 Correct 98 ms 31852 KB Output is correct