QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#179078#6894. CircuitPPP#AC ✓894ms7220kbC++172.1kb2023-09-14 17:36:542023-09-14 17:36:55

Judging History

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

  • [2023-09-14 17:36:55]
  • 评测
  • 测评结果:AC
  • 用时:894ms
  • 内存:7220kb
  • [2023-09-14 17:36:54]
  • 提交

answer

#ifdef DEBUG
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

//const ll mod = 1000000007;
const ll mod = 998244353;

#define X first
#define Y second

ll pew(ll a, ll b)
{
    ll res = 1;
    while (b>0)
    {
        if (b&1) res = res*a%mod;
        b >>= 1;
        a = a*a%mod;
    }
    return res;
}



void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<vector<pair<ll,ll>>> g(n);
    for (ll i=0;i<m;i++)
    {
        ll u, v, c;
        cin >> u >> v >> c;
        u--, v--;
        g[u].push_back({v,c});
    }
    ll mn = mod*mod, C = 0;
    for (int i=0;i<n;i++)
    {
        vector<ll> d(n,mod*mod), cnt(n);
        for (int j=0;j<g[i].size();j++)
        {
            int v = g[i][j].X, c = g[i][j].Y;
            if (v>=i) d[v] = c, cnt[v] = 1;
        }
        vector<int> was(n);
        for (int w=0;w<n-i;w++)
        {
            int p = -1;
            for (int u=i;u<n;u++)
            {
                if (was[u]==1) continue;
                if (p==-1 or d[u]<d[p]) p = u;
            }
            was[p] = 1;
            if (p==i)
            {
                if (d[i]==mod*mod) continue;
                if (mn>d[i]) mn = d[i], C = 0;
                if (d[i]==mn) C = (C+cnt[i])%mod;
            }
            for (int j=0;j<g[p].size();j++)
            {
                int v = g[p][j].X;
                if (v<i) continue;
                ll D = d[p]+g[p][j].Y;
                if (d[v]>D)
                {
                    d[v] = D, cnt[v] = 0;
                }
                if (d[v]==D) cnt[v] = (cnt[v]+cnt[p])%mod;
            }
        }
    }
    if (mn==mod*mod) cout << -1 << " " << -1 << "\n";
    else cout << mn << " " << C << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//#ifdef DEBUG
    //freopen("input.txt", "r", stdin);
//#endif
    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: 894ms
memory: 7220kb

input:

13
3 4
1 2 4
2 1 3
2 3 2
3 1 1
10 12
1 2 1
2 3 1
3 4 1
4 1 1
4 5 1
5 6 1
6 7 1
7 4 1
3 8 1
8 9 1
9 10 1
10 3 1
2 1
1 2 1
12 20
1 2 3
2 1 3
1 3 2
3 2 1
1 4 1
4 5 1
5 2 1
1 6 1
6 2 2
1 7 1
7 2 2
1 8 1
8 2 2
1 9 1
9 2 2
2 10 1
10 1 2
2 11 1
11 12 1
12 1 1
500 249500
1 2 1
1 3 2
1 4 3
1 5 4
1 6 5
1 7 6
...

output:

7 2
4 3
-1 -1
6 21
500 616118143
1002500000 124750
566 124750
2 124750
-1 -1
500098704 2
8500 207839182
116655401 5046
500000000000 1

result:

ok 13 lines