QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#500719 | #3815. Weak pseudorandom generator | PetroTarnavskyi# | WA | 0ms | 3644kb | C++20 | 1.8kb | 2024-08-01 18:48:03 | 2024-08-01 18:48:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int N = 1 << 10;
const LL LINF = 1e18;
vector<PII> g[N];
bool used[N];
VI toposort;
LL dp[N][N];
int idx[N];
template<typename T>
void updMin(T& a, T b)
{
a = min(a, b);
}
void dfs(int v)
{
used[v] = true;
for (auto [to, w] : g[v])
{
if (!used[to])
dfs(to);
}
toposort.PB(v);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
FOR(i, 0, m)
{
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
g[u].PB({v, w});
g[v].PB({u, w});
}
int s1, t1, s2, t2;
cin >> s1 >> t1 >> s2 >> t2;
s1--;
t1--;
s2--;
t2--;
dfs(s1);
if (!used[s2])
dfs(s2);
reverse(ALL(toposort));
int k = SZ(toposort);
fill(idx, idx + n, -1);
FOR(i, 0, k)
idx[toposort[i]] = i;
for (int v : toposort)
cerr << v << " ";
cerr << endl;
if (idx[t2] == -1 || idx[t2] == -1)
{
cout << "NIE\n";
return 0;
}
FOR(i, 0, k)
FOR(j, 0, k)
dp[i][j] = LINF;
dp[idx[s1]][idx[s2]] = 0;
FOR(i, 0, k)
{
int u = toposort[i];
FOR(j, 0, k)
{
int v = toposort[j];
if (i < j || v == t2)
{
for (auto [to, w] : g[u])
{
updMin(dp[idx[to]][j], dp[i][j] + w);
}
}
if (i > j || u == t1)
{
for (auto [to, w] : g[v])
{
updMin(dp[i][idx[to]], dp[i][j] + w);
}
}
}
}
LL ans = dp[idx[t1]][idx[t2]];
if (ans == LINF)
cout << "NIE\n";
else
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3644kb
input:
5 3 2 1 0
output:
NIE
result:
wrong output format Expected integer, but "NIE" found