QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#377653 | #7991. 最小环 | gogo11# | WA | 104ms | 39628kb | C++14 | 1.7kb | 2024-04-05 16:25:55 | 2024-04-05 16:25:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define lowbit(x) ((x) & (-x))
constexpr int N = 2e5 + 10;
constexpr int M = 5e5 + 10;
constexpr ll mod = (1LL<<20);
constexpr int INF = 0x3f3f3f3f;
constexpr ll Base = 131;
constexpr int MAXBIT = 30;
#define pb push_back
constexpr int maxn = 3e5 + 10;
constexpr ll LNF = 0x3f3f3f3f3f3f3f3f;
#define int long long
ll n, m, ans = LNF;
int top = 0;
pll st[maxn];
bool vis[maxn], inst[maxn];
vector<pll> g[maxn];
void dfs(int u, ll fauw = 0)
{
vis[u] = 1;
inst[u] = true;
st[++ top] = {u, fauw};
for(auto it : g[u])
{
ll v = it.first, w = it.second;
if(vis[v])
{
if(inst[v])
{
// vector<int> path;
// path.pb(v);
int t = top;
ll res = w;
while(st[t].first != v)
{
// path.pb(st[t].first);
res += st[t--].second;
}
if(res < ans) ans = res;
// cout << res << " -> ";
// for(auto j : path)
// cout << j << " ";
// cout << "\n";
}
continue;
}
dfs(v, w);
}
inst[u] = false;
-- top;
}
void solve()
{
cin >> n >> m;
for(int i = 1; i <= m; i ++)
{
ll u, v, w;
cin >> u >> v >> w;
g[u].pb({v, w});
}
for(int i = 1; i <= n; i ++)
if(!vis[i]) dfs(i);
if(ans == LNF) cout << -1 << '\n';
else cout << ans << "\n";
}
signed main()
{
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// #endif
int _ = 1;
// cin >> _;
while (_--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 13196kb
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: 13192kb
input:
1 0
output:
-1
result:
ok single line: '-1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 12280kb
input:
1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 91ms
memory: 39628kb
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:
-1
result:
ok single line: '-1'
Test #5:
score: 0
Accepted
time: 92ms
memory: 20716kb
input:
248016 248896 82688 82755 592665252 202847 203260 294408121 26821 28237 269132335 150967 152178 3125829 246069 247390 29492546 7470 7673 55843492 33975 35414 442802995 28451 28948 193736988 34484 34637 84441058 60168 60309 501991354 79579 79844 26854803 239672 239706 111702667 73548 73658 149840530 ...
output:
98674714245
result:
ok single line: '98674714245'
Test #6:
score: -100
Wrong Answer
time: 104ms
memory: 21720kb
input:
270530 271285 80489 81855 218173724 188930 190845 783975756 29830 30626 22189315 234320 234472 70840355 198096 198272 300313423 224194 226906 105128197 115010 115834 37228105 134788 135583 18647938 257292 257358 98569041 146988 147215 69398857 248752 250002 409565478 62128 63751 839744551 121918 122...
output:
136244513930
result:
wrong answer 1st lines differ - expected: '133486910467', found: '136244513930'