이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 5010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define bitcount(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ss(x) (int)x.size()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
void add(int &x, int k)
{
x += k;
x %= mod;
if(x < 0) x += mod;
}
void del(int &x, int k)
{
x -= k;
x %= mod;
if(x < 0) x += mod;
}
map<int,int> cnt[maxn],f[maxn];
array<int,4> edge[maxn];
vector<array<int,3>> ke[maxn];
int n,m;
main()
{
#define name "TASK"
if (fopen(name ".inp", "r"))
{
freopen(name ".inp", "r", stdin);
freopen(name ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
vi nen;
fo(i,1,m)
{
cin >> edge[i][0] >> edge[i][1] >> edge[i][2] >> edge[i][3];
nen.pb(edge[i][2]);
}
sort(all(nen));
nen.erase(unique(all(nen)),nen.end());
fo(i,1,m)
{
edge[i][2] = lower_bound(all(nen),edge[i][2]) - nen.begin() + 1;
ke[edge[i][0]].push_back({edge[i][1],edge[i][2],edge[i][3]});
ke[edge[i][1]].push_back({edge[i][0],edge[i][2],edge[i][3]});
cnt[edge[i][0]][edge[i][2]]++;
cnt[edge[i][1]][edge[i][2]]++;
}
priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>> q;
q.push({0,{1,0}});
f[1][0] = 0;
while(ss(q))
{
auto [du,u] = q.top();
q.pop();
auto [x,color] = u;
if(du != f[x][color]) continue;
for(auto [v,c,p] : ke[x])
{
if(cnt[x][c] == 1 and (!f[v].count(c) or minimize(f[v][c],du)))
{
f[v][c] = du;
q.push({du,{v,c}});
}
if(cnt[x][c] == 2)
{
if(c == color and (!f[v].count(0) or minimize(f[v][0],du)))
{
f[v][0] = du;
q.push({du,{v,0}});
}
}
if(!f[v].count(c) or minimize(f[v][c],du + p))
{
f[v][c] = du + p;
q.push({du + p,{v,c}});
}
}
}
int ans = inf;
fo(i,0,ss(nen)) if(f[n].count(i)) minimize(ans,f[n][i]);
cout << (ans == inf ? -1 : ans);
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
61 | main()
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | freopen(name ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | freopen(name ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |