QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#560005#853. Flat Organizationrotcar07WA 10ms11764kbC++201.9kb2024-09-12 11:22:592024-09-12 11:23:00

Judging History

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

  • [2024-09-12 11:23:00]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:11764kb
  • [2024-09-12 11:22:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=2e3+5;
constexpr int INF=1e9+1;
int d[maxn][maxn];
int n,dfn[maxn],low[maxn],tqm,tot,fa[maxn];bool vis[maxn];
stack<int> s;
int g[maxn][maxn];
void dfs(int p){
    dfn[p]=low[p]=++tqm;vis[p]=1;s.push(p);
    for(int i=1;i<=n;i++)if(d[p][i]) low[p]=min(low[p],dfn[i]?vis[i]?low[i]:low[p]:(dfs(i),low[i]));
    if(dfn[p]==low[p]){
        ++tot;
        while(!s.empty()){
            int pp=s.top();s.pop();
            fa[pp]=tot;vis[pp]=0;
            if(pp==p) break;
        }
    }
}
long long dp[maxn];
int lst[maxn],to[maxn];
pair<int,int> sb[maxn][maxn];
inline void solve(){
    cin>>n;for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++) cin>>d[i][j];
    if(n==2) return cout<<"NO\n",void();
    for(int i=1;i<=n;i++) dfn[i]=low[i]=vis[i]=0;tqm=tot=0;while(!s.empty()) s.pop();
    for(int i=1;i<=n;i++) if(!dfn[i]) dfs(i);
    for(int i=1;i<=tot;i++)for(int j=1;j<=tot;j++) g[i][j]=(i==j?0:INF);
    // for(int i=1;i<=n;i++) cout<<fa[i]<<' ';cout<<'\n';
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)if(d[i][j]){
        int fi=fa[i],fj=fa[j];
        if(g[fi][fj]>d[i][j]){
            g[fi][fj]=d[i][j];
            sb[fi][fj]=make_pair(i,j);
        }
    }
    dp[1]=0;
    for(int i=2;i<=tot;i++){
        dp[i]=1e18;
        int curm=1;
        for(int j=1;j<i;j++){
            if(g[i][curm]>g[i][j]) curm=j;
            if(g[i][curm]<INF){
                if(dp[j]+g[i][curm]<dp[i]) dp[i]=dp[j]+g[i][curm],lst[i]=curm,to[i]=j;
            }
        }
    }
    vector<pair<int,int>> ans;
    int z=tot;
    while(z!=1){
        ans.emplace_back(sb[z][lst[z]]);
        z=to[z];
    }
    cout<<"YES\n";
    cout<<ans.size()<<' '<<dp[tot]<<'\n';
    for(auto x:ans) cout<<x.first<<' '<<x.second<<'\n';
}
int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;cin>>t;
    while(t--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 7652kb

input:

1
5
0 1 0 6 11
0 0 1 6 12
2 0 0 7 12
0 0 0 0 4
0 0 0 0 0

output:

YES
2 10
1 4
4 5

result:

ok OK!

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 11764kb

input:

100
5
0 1 0 6 11
0 0 1 6 12
2 0 0 7 12
0 0 0 0 4
0 0 0 0 0
1
0
2
0 0
7 0
2
0 1000000000
0 0
3
0 0 5
6 0 0
0 7 0
3
0 4 6
0 0 0
0 1 0
3
0 4 0
0 0 0
6 3 0
3
0 0 0
10 0 6
3 0 0
3
0 1999999998 1999999999
0 0 1999999998
0 0 0
50
0 105800 801 1800 64800 0 259200 288801 72201 12801 125000 20001 28801 33800 ...

output:

YES
2 10
1 4
4 5
YES
0 0
NO
NO
YES
0 0
YES
1 4
1 2
YES
1 3
3 2
YES
2 9
2 3
3 1
YES
2 1000000000000000000
2 3
3 1
YES
3 602
4 33
11 47
34 39
YES
3 649
27 12
32 45
17 29
YES
5 1209
1 18
14 35
35 4
4 25
25 12
YES
3 844
3 8
1 41
14 21
YES
3 866
17 35
35 44
46 26
YES
4 1066
10 28
36 24
24 2
37 8
YES
3 11...

result:

wrong output format Expected int32, but "1000000000000000000" found