QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#641375#7991. 最小环ucup-team3519TL 0ms3868kbC++171.2kb2024-10-14 20:15:132024-10-14 20:15:13

Judging History

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

  • [2024-10-14 20:15:13]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3868kb
  • [2024-10-14 20:15:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
typedef __int128_t LLL;
#define fi first
#define lb lower_bound
#define se second
#define V vector
#define pb push_back
#define all0(x) (x).begin(), (x).end()
#define all1(x) (x).begin() + 1, (x).end()

const int INF = 2e9 + 100;
const LL INFLL = 8e18 + 1000;

const int MN = 3e5 + 100;

void solve() {
    int n, m; cin >> n >> m;

    V<V<LL>> dis(n + 1, V<LL>(n + 1, INFLL / 2));
    for(int i = 1; i <= m; i++) {
        int a, b, c; cin >> a >> b >> c;
        dis[a][b] = min(dis[a][b], (LL)c);
    }

    for(int k = 1; k <= n; k++) {
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
            }
        }
    }


    LL ans = 1e18;
    for(int i = 1; i <= n; i++) ans = min(ans, dis[i][i]);



    if(ans >= 1e17) {
        cout << -1 << endl;
    } else cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t = 1; 
    // cin >> t;
    while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

7

result:

ok single line: '7'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

1 0

output:

-1

result:

ok single line: '-1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

1 1
1 1 1

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Time Limit Exceeded

input:

258420 258419
33061 33062 767169384
212916 212917 1741339
229881 229882 896760805
173467 173468 273055172
233189 233190 800433307
10157 10158 126766550
174605 174606 552176083
224030 224031 886617880
229102 229103 783848581
67588 67589 510826095
233648 233649 879695751
214453 214454 867104578
153140...

output:


result: