QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#600775#9230. Routing K-Codesucup-team4352#WA 170ms35052kbC++232.9kb2024-09-29 19:03:352024-09-29 19:03:36

Judging History

你现在查看的是最新测评结果

  • [2024-09-29 19:03:36]
  • 评测
  • 测评结果:WA
  • 用时:170ms
  • 内存:35052kb
  • [2024-09-29 19:03:35]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define lowbit(x) (x&-x)
#define log(x) (31^__builtin_clz(x))
using namespace std;
vector<int>e[200005];
struct Data{
    int dep;
    ll sum,res,tot;
    ll out(){
        return sum+tot;
    }
};
Data operator+(Data a,Data b){
    return {max(a.dep,b.dep),a.sum+b.sum,a.res+b.res,a.tot+b.tot};
}
Data upd(Data now){
    now.dep++;
    now.sum=now.sum*2+1;
    now.res=now.res*2+1;
    return now;
}
vector<Data>dat[200005];
Data dfs1(int x,int f){
    Data now={0,0,0};
    vector<ll>s;
    for(int i=0;i<e[x].size();i++){
        int u=e[x][i];
        if(u==f)continue;
        now=now+(dat[x][i]=dfs1(u,x));
        s.push_back(dat[x][i].res);
    }
    now=upd(now);
    if(s.size()==2)now.tot+=min(s[0],s[1]);
    return now;
}
void dfs2(int x,int f,Data p){
    for(int i=0;i<e[x].size();i++){
        int u=e[x][i];
        if(u==f)dat[x][i]=p;
    }
    for(int i=0;i<e[x].size();i++){
        int u=e[x][i];
        if(u==f)continue;
        Data now={0,0,0};
        vector<ll>s;
        for(int j=0;j<e[x].size();j++){
            if(i==j)continue;
            now=now+dat[x][j];
            s.push_back(dat[x][j].res);
        }
        now=upd(now);
        if(s.size()==2)now.tot+=min(s[0],s[1]);
        dfs2(u,x,now);
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    for(int i=1;i<=n;i++){
        if(e[i].size()>3){
            cout<<"NIE\n";
            return;
        }
        dat[i].resize(e[i].size());
    }
    if(m>n-1){
        cout<<"NIE\n";
        return;
    }
    dfs1(1,0);
    dfs2(1,0,{0,0,0});
    ll ans=1e18;
    for(int i=1;i<=n;i++){
        if(e[i].size()==1){
            if(dat[i][0].dep>31)continue;
            ans=min(ans,upd(dat[i][0]).out());
        }
        if(e[i].size()==2){
            if(dat[i][0].dep>31||dat[i][1].dep>31)continue;
            ans=min(ans,upd(dat[i][0]+dat[i][1]).out());
            if(dat[i][0].dep==1)ans=min(ans,upd(dat[i][1]).out());
            if(dat[i][1].dep==1)ans=min(ans,upd(dat[i][0]).out());
        }
        if(e[i].size()==3){
            if(dat[i][0].dep>31||dat[i][1].dep>31||dat[i][2].dep>31)continue;
            if(dat[i][0].dep==1)ans=min(ans,upd(dat[i][1]+dat[i][2]).out()+min(dat[i][1].res,dat[i][2].res));
            if(dat[i][1].dep==1)ans=min(ans,upd(dat[i][0]+dat[i][2]).out()+min(dat[i][0].res,dat[i][2].res));
            if(dat[i][2].dep==1)ans=min(ans,upd(dat[i][0]+dat[i][1]).out()+min(dat[i][0].res,dat[i][1].res));
        }
    }
    if(ans==1e18)cout<<"NIE\n";
    else cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0), 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: 3612kb

input:

4 3
1 2
1 3
1 4

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3520kb

input:

4 6
1 2
2 3
3 4
4 1
1 3
2 4

output:

NIE

result:

ok single line: 'NIE'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3776kb

input:

10 10
9 3
5 10
1 4
10 8
8 3
7 3
9 6
8 6
7 2
4 5

output:

NIE

result:

ok single line: 'NIE'

Test #4:

score: 0
Accepted
time: 170ms
memory: 34768kb

input:

200000 199999
172774 188052
195063 155577
38023 148303
30605 155047
170238 19344
46835 58255
154268 109062
197059 116041
136424 12058
42062 149807
109545 115380
132322 51106
16706 162612
62234 31319
195735 80435
173898 84051
19876 102910
186924 9136
123094 117097
145054 173049
137364 152731
82662 18...

output:

NIE

result:

ok single line: 'NIE'

Test #5:

score: 0
Accepted
time: 166ms
memory: 34768kb

input:

200000 199999
168192 30733
164413 46673
175210 2329
69389 67102
33991 152553
91061 55265
166724 117726
90148 157176
34831 12213
60756 105488
121891 155192
82202 155666
102083 156661
38968 75200
190004 107321
72436 92732
64314 65004
39210 91106
70455 173568
179742 29844
126232 19552
133509 110602
131...

output:

20980030044349

result:

ok single line: '20980030044349'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3768kb

input:

4 3
1 2
1 3
1 4

output:

6

result:

ok single line: '6'

Test #7:

score: 0
Accepted
time: 165ms
memory: 34560kb

input:

199021 199020
189105 111001
147300 187047
67395 102319
25317 152109
56495 115535
11656 19974
119178 6528
84571 159100
198873 156684
21161 163040
91720 165273
168305 140152
104884 119802
131 177991
35930 74934
27528 278
177640 162738
118439 69472
20365 85043
184995 54207
64542 188847
97881 167717
188...

output:

NIE

result:

ok single line: 'NIE'

Test #8:

score: -100
Wrong Answer
time: 160ms
memory: 35052kb

input:

200000 199999
145608 31176
94180 155303
112924 85699
196865 176102
34049 30841
84924 191665
164317 97582
10102 125492
114493 20622
127660 194591
183851 21461
167689 53839
59189 126425
135853 79950
173910 4196
8134 182272
42157 63799
5109 182005
197391 154014
93467 130380
1508 66644
129681 199910
677...

output:

25146839514611

result:

wrong answer 1st lines differ - expected: '25146839515965', found: '25146839514611'